Close, but not completely accurate.

binmode is not part of the buffered IO scheme - in fact, the last bit of the perldoc for binmode explicitly says:

binmode() is not only important for readline() and print() operations, but also when using read(), seek(), sysread(), syswrite() and tell() (see the perlport manpage for more details). See the "$/" and "$\" variables in the perlvar manpage for how to manually set your input and output line-termination sequences.

Now, as far as the original post is concerned, if you are only ever worried about a single argument in ARGV, this would be sufficient:

if (! @ARGV) { use open ':raw'; # implicit binmode on each open open(ARGV, '-'); } else { use open ':raw'; open(ARGV, shift @ARGV); # Yeah, it's the two-arg version, # because that's what perl does with <> # see perlopentut } # ... now go do all that sysread stuff.

If, however, there are possibly multiple files available, you'll have to get more creative:

my @files = (@ARGV)?@ARGV:qw(-); NEXTFILE: while (@files) { use open ':raw'; open(ARGV, shift @files); # do sysread stuff here # don't forget that an eof here may not be a "real" eof, # but a signal to go to the next file }
Another possibility is to tie several files together into a single hash which does all the opening in the background. That's left as an exercise for the reader, of for some other response.

Update: Oops, as Mr. Muskrat pointed out. Fixed.

--
@/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/

In reply to Re^2: binmode and sysread on <> by fizbin
in thread binmode and sysread on <> by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.