note
Abigail
The answers are:
<ul><li>Yes
<li>Yes
<li>Just because.... ;-)
</ul>
In a few cases, <code>$_</code> is implicitely <em>localized</em>:
in the block/expression of <code>map</code> and <code>grep</code>
and in the block of a <code>foreach</code> that doesn't have
its own iterator mentioned. (If the iterator is mentioned,
with no <code>my</code> preceeding it, the iterator is
localized too). This is all documented where <code>foreach</code>,
<code>map</code> and <code>grep</code> are documented:
<tt>perlsyn</tt> and <tt>perlfunc</tt>.
<p>
There is a difference between <code>foreach</code> and
<code>while</code> because they are two totally different
things. <code>foreach</code> <strong>always</strong> assigns
to a variable when looping over a list, while <code>while</code>
normally doesn't. It's just that <code>while (<>)</code>
is an exception and only when there's a single diamond
operator there's an implicite assignment to <code>$_</code>.
<p>-- Abigail
96369
96369