note
ihb
<p>Dispite that many has pointed out that
<code>
while (my $line = <DATA>) { ... }
while (defined (my $line = <DATA>)) { ... }
</code>
are identical, your first remark is true. The problem lies elsewhere:
<code>
while (<DATA>) { ... }
</code>
<b>doesn't localize <code>$_</code></b> and thus leaves <code>$_</code> undefined after the loop.
<code>
while (my $line = <DATA>) { ... }
</code>
doesn't suffer from this as it doesn't touch <code>$_</code>.</p>
<p>If put in a subroutine this innocent little bug cause a serious headache while trying to find out why <code>$_</code> all of a sudden is undefined.</p>
<p><tt>ihb</tt></p>
<div class="pmsig"><div class="pmsig-223894">
<p><i><small>
See [doc://perltoc] if you don't know which perldoc to read!<br />
</small></i></p>
</div></div>
484238
484330