Mega Code Archive

 
Categories / Perl / File
 

To read a number of bytes from a file

#!/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);