I guess bottom line: Don't use <> bracket when reading binary files!
#!/usr/bin/perl use strict; use warnings; my $data = <<EOF; first second EOF print "data var in text mode - this works...\n"; print "$data\n"; print "----\n"; open my $fh, '<', \$data; binmode $fh; my $num_bytes = read ($fh, my $buf, 20000); print "read () binary doesn't completely work..the normal way to read +binary\n"; print "this is Windows machine and I don't see both CR and LF characte +rs\n"; print "but I think that is due to Perl translation of line endings\n"; print "bytes read = $num_bytes\n"; print '',$buf; print "----\n"; print "using angle operator for binary read doesn't work\n"; print "I've never tried this before and I'm not sure why\n"; print "this doesn't work - need explanation of the angle <>op.\n"; close $fh; open $fh, '<', \$data or die "$!"; binmode $fh; my $bdata = <$fh>; print '',$bdata; __END__ data var in text mode - this works... first second ---- read () binary doesn't completely work..the normal way to read binary this is Windows machine and I don't see both CR and LF characters but I think that is due to Perl translation of line endings bytes read = 13 first second ---- using angle operator for binary read doesn't work I've never tried this before and I'm not sure why this doesn't work - need explanation of the angle <>op. first
In reply to Re^5: Error binmode() on unopened filehandle
by Marshall
in thread Error binmode() on unopened filehandle
by RedJeep
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |