Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: File Reading and Closing confusion

by cdarke (Prior)
on Aug 08, 2010 at 16:10 UTC ( #853665=note: print w/ replies, xml ) Need Help??

in reply to File Reading and Closing confusion

Another difference not mentioned by the estemed monks above:

while (<FH>) {...}
assigns a line to $_ on each iteration of the loop, as mentioned, however outside a loop it does not. Just plain
does read a line from the file, but does not assign it to $_. So far as I know it is not stored. The assignment to $_ is magic that only occurs inside the condition of a while loop. $line = <FH>; works as expected - the line which has been read is assigned to $line.

By the way, if you use sysread the you should open with sysopen, but there is also read which is used after our old friend open. With read you can specify how many characters to read, which can also be done with $/ (although I find read easier to um, read).

Comment on Re: File Reading and Closing confusion
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2015-10-07 18:49 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (197 votes), past polls