Re: binmode and <>



Larry wrote:
Dr.Ruud wrote:
Larry schreef:
Larry:

Is there any way to get "while (<>)" to use binmode? I can't figure
it out since binmode is supposed to be called after the file is
already open but before it is read for the first time, so you can't
call it before the loop, nor can you call it inside the loop.

I would also like to use binmode for 1-liners using -n or -p
switches.

P.S. ... in case anyone is wondering why I would want to use <>
together with binmode (they usually don't go together) is that I have
a .csv file generated by Excel. Each record is terminated by "\r\n",
however inside each record there are some "\n" characters,
representing multi-line cells in the spreadsheet. So I want to set
$/ = "\r\n" and turn on binmode.

Try

perl -MO=Deparse -ne1

and you'll find the name of the handle.


I know the handle is ARGV, but knowing the name won't help. The handle
won't be open before the "while" loop so I can't "bindmode" it then.
Inside the "while" loop, it will already be too late to call "binmode",
since the line has already been read.

I think he meant you could binmode ARGV in a BEGIN block (untested) but
John's suggestion was, as usual, The Right Answer :P

-jp

.