Instead of using a temporary disk file, I thought I'd try to use a memory file (scalar ref), but I need to be able to use the handle with binmode $fh, ':raw' (or equivalent). Is this possible?
use strict; use warnings; my $mf; my $fh; # mem write open $fh, '>', \$mf or die $!; print $fh "hello\n"; close $fh; # mem read open $fh, '<', \$mf or die $!; binmode $fh, ':raw'; while (<$fh>){ print "mem: " . (unpack "H*", $_) . "\n"; } close $fh; # file write open $fh, '>', 'file.txt' or die $!; print $fh "hello\n"; close $fh; # file read open $fh, '<', 'file.txt' or die $!; binmode $fh, ':raw'; while (<$fh>){ print "file: " . (unpack "H*", $_) . "\n"; }
Output... note the difference after the 'f'. I need the mem file to reflect that of :raw like the value for file.
mem: 68656c6c6f0a file: 68656c6c6f0d0a
In reply to Is there a way to open a memory file with binmode :raw? by stevieb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |