Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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 scrutinizing the Monastery: (9)
As of 2021-04-19 12:39 GMT
Find Nodes?
    Voting Booth?

    No recent polls found