filehandle - Why do I get "Bad File Descriptor" when I try to read a file with Perl? -


i'm trying read binary file 40 bytes @ time, check see if bytes 0x00, , if ignore them. if not, write them out file (basically cutting out large blocks of null bytes).

this may not efficient way this, i'm not worried that. however, right i'm getting "bad file descriptor" error , cannot figure out why.

my $comp = "\x00" * 40; $byte_count = 0;  $infile = "/home/magicked/image1"; $outfile = "/home/magicked/image1_short";  open in, "<$infile"; open out, ">$outfile"; binmode in; binmode out; ($buf, $data, $n); while (read (in, $buf, 40)) { ### problem here ###   $boo = 1;   ($i = 0; $i < 40; $i++) {     if ($comp[$i] != $buf[$i]) {       $i = 40;       print out $buf;       $byte_count += 40;     }   } } die "problems! $!\n" if $!;  close out; close in; 

i marked comment breaking. help!

you might want check if open doesn't return error.

open in, "<$infile" or die "can't open $infile: $!"; 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -