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

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
<FH>;
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2014-09-17 01:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (55 votes), past polls