Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: binmode and one-liners

by diotalevi (Canon)
on Jul 01, 2007 at 15:27 UTC ( [id://624313]=note: print w/replies, xml ) Need Help??


in reply to Re^2: binmode and one-liners
in thread binmode and one-liners

You'd have to be able to call binmode between the implicit file open, and the reading of the first line. And you just can't interject code there.
Yes you can. eof with no parens and no parameters starts the ARGV magic but doesn't read any lines.

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^4: binmode and one-liners (eof reads)
by tye (Sage) on Jul 02, 2007 at 20:55 UTC

    After my previous reply, I found the time and facilities and ran a quick test and found two mistakes in your suggestion. First, it is eof() (with parens) not eof without parens that triggers ARGV magic.

    Second, as I suspected, eof() does read ahead:

    % perl -del existingFile.txt DB<1> x eof() 0 '' DB<2> x sysseek(*ARGV,0,1) 0 4096 DB<3>

    So, if on a platform where binmode mattered, binmode() would not have been in effect for the first 4096 (resulting) bytes of the file. (But note that you don't need such a platform to perform this test.) Part of the problem here is that the impact of binmode is handled by the underlying I/O layers, not by Perl, so the bytes pre-read have already passed through the layer where binmode would be applied (but wasn't).

    If there is some way to get eof without parens to trigger an ARGV-magic implicit open, then I couldn't figure it out and so didn't test it. So please describe it in more detail.

    - tye        

Re^4: binmode and one-liners
by tye (Sage) on Jul 01, 2007 at 16:46 UTC

    I'll believe that when I see test code to demonstrate it. My recollection is that eof reads ahead to see whether you are at EOF rather than just returning whether Perl already knew that you were at EOF.

    I can see eof allowing code to run just before an implicit close / open, but I'd be surprised to find eof not causing an implicit read() after it caused an implicit open().

    Sorry, I'm not in a position to test it myself at the moment.

    - tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://624313]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-04-20 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found