in reply to Re: Mysteries of unpack("a", ...)
in thread Mysteries of unpack("a", ...)
I am not at all sure that STDIN can even be opened in binary mode at all!
Yes it works the same on STDIN as other handles. Specifically, it disables crlf→lf conversion on Windows machines, it stops treating chr(26) as the end of file on non-PerlIO Windows builds, and does nothing elsewhere.
I mean CTL-C, CTL-Z mean things to STDIN although these are certainly valid binary values.
No they don't. They may mean something to the tty/console, but STDIN doesn't even know about the Ctrl key. It doesn't treat character 3 or 26 specially.
>perl -e"print qq{\x03\x1A}" | perl -le"print uc unpack 'H*', <STDIN>" 031A $perl -e'print qq{\x03\x1A}' | perl -le'print uc unpack "H*", <STDIN>' 031A
If you want to read binary data, open a file in binmode... local $/ = undef; is not needed.
Not true at all. $/ is quite useful on binary files.
my @records = map parse_rec($_), map /(.{$RECSIZE})/sg, do { local $/; <$fh> };
and
my @records; local $/ = \$RECSIZE; local *_; while (<$fh>) { push @records, parse_rec($_); }
are equivalent to
my @records; local *_; while (read($fh, $_, $RECSIZE)) { push @records, parse_rec($rec); }
Mind you, read is unaffected by $/, but that has nothing to do with whether the file is binary or not.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Mysteries of unpack("a", ...)
by Marshall (Canon) on Jan 03, 2009 at 17:09 UTC | |
by ikegami (Patriarch) on Jan 03, 2009 at 18:17 UTC |