00H IS ASCII.
> Is there a way to read binary files,
> like the "b" flag used with fopen in C ?
perldoc -f binmode
> I'd also like to know how to read one
> character at a time, instead of reading a whole line.
Setting the input record separator to a reference of a numeric literal.
$/ = \1; # reading from <filehandler> one character at a time
perldoc -f read
perldoc -f getc
John
--
use Perl;
program
fulfillment
I can't say for certain but I've had horrible luck reading and writing
binary files on Windows without the following lines. Corrupted files and
general weirdness. No idea why it even affects it. Too lazy to
investigate. Here they are, good luck:
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
I don't know if just use CGI::Carp would suffice. I'm happy this works and
don't change it, and those are really useful for what I'm doing anyway so I
don't consider it wasteful
Erik
open(BINFILE, "</tmp/binfile.exe");
binmode(BINFILE); # tell perl the file handle is a binary file
local $/=undef; # undefined input separator so the whole file gets sucked in
my $complete_file = <BINFILE>;
close(BINFILE);
You will need to binmode() any file handle you intend to write this to as well.
Regards,
David
"Apokrif" <apok...@yahoo.com> wrote in message
news:dfc75420.02082...@posting.google.com...
>I can't say for certain but I've had horrible luck reading and writing
>binary files on Windows without the following lines. Corrupted files and
>general weirdness. No idea why it even affects it. Too lazy to
>investigate. Here they are, good luck:
>
>use CGI;
>use CGI::Carp qw/fatalsToBrowser/;
No. These lines have nothing whatsoever to with binary
files, except in so far as all CGI scripts should have them
(and use them properly.
To read and write binary files on non-Unix systems, you want
the binmode function, see the docs for further info:
perldoc -f binmode
--
Regards, Helgi Briem
helgi AT decode DOT is