<?xml version="1.0" encoding="windows-1252"?>
<node id="853665" title="Re: File Reading and Closing confusion" created="2010-08-08 12:10:24" updated="2010-08-08 12:10:24">
<type id="11">
note</type>
<author id="541305">
cdarke</author>
<data>
<field name="doctext">
Another difference not mentioned by the estemed monks above:&lt;code&gt;
while (&lt;FH&gt;) {...}
&lt;/code&gt;assigns a line to $_ on each iteration of the loop, as mentioned, however &lt;i&gt;outside&lt;/i&gt; a loop it does not.  Just plain &lt;code&gt;
&lt;FH&gt;;
&lt;/code&gt;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 [doc://while] loop.
&lt;code&gt;$line = &lt;FH&gt;;&lt;/code&gt; works as expected - the line which has been read is assigned to &lt;code&gt;$line&lt;/code&gt;.&lt;br&gt;&lt;br&gt;By the way, if you use [doc://sysread] the you should open with [doc://sysopen], but there is also [doc://read] which is used after our old friend [doc://open].  With [doc://read] you can specify how many characters to read, which can also be done with $/ (although I find [doc://read] easier to um, read).
</field>
<field name="root_node">
853652</field>
<field name="parent_node">
853652</field>
</data>
</node>
