To read a number of bytes from a file: $bytes_read = read(filehandle, $var, $length, $offset);
#!/usr/bin/perl -w
# Usage:
# read.pl infile outfile
#
$input = $ARGV[0];
$output = ">" . $ARGV[1];
open(INPUT, $input) or die "Can't open $input due to $!.";
open(OUTPUT, $output) or die "Can't open $output due to $!.";
$length = 1024;
$bytes_read = read(INPUT, $var, $length);
while ($bytes_read > 0) {
print OUTPUT $var;
$bytes_read = read(INPUT, $var, $length);
}
close (INPUT);
close (OUTPUT);
Related examples in the same category