Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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).

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 surveying the Monastery: (5)
As of 2016-10-26 00:01 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (330 votes). Check out past polls.