title: behavior of new 'each @array' in scalar context
body: <p>Perl 5.14 gives us the extended <code>each</code> function which operates on arrays as well as hashes:</p>
  
  <blockquote>
    <p>When called in list context, returns a 2-element list consisting of the key and value for the next element of a hash, or the index and value for the next element of an array, so that you can iterate over it.  When called in scalar context, returns only the key (not the value) in a hash, or the index in an array.</p>
  </blockquote>
  
  <p>An example using list context works:</p>
  
  <pre><code>perl -E 'say $^V'
  
  v5.14.0
  
  perl -E '@a = (1..10); while (my ($i, $elem) = each @a) {say "\$a[$i] = $elem"}'
  
  $a[0] = 1
  $a[1] = 2
  $a[2] = 3
  $a[3] = 4
  $a[4] = 5
  $a[5] = 6
  $a[6] = 7
  $a[7] = 8
  $a[8] = 9
  $a[9] = 10
  </code></pre>
  
  <p>however in scalar context, I get nothing:</p>
  
  <pre><code>perl -E '@a = (1..10); while (my $i = each @a) {say $i}'
  </code></pre>
  
  <p>Can anyone offer any insight? I have a feeling that this will be a head slapper when someone points out my error, but perhaps not.</p>
  
  <p><s>Edit: In fact the <code>while</code> loop has nothing to do with it:</p>
  
  <pre><code>perl -E '@a = (1..10); $i = each @array; say $i'
  </code></pre>
  
  <p>gives no output either.</s> <code>s'@array'@a'</code> oops.</p>
  
  <p>Edit 2:</p>
  
  <p>As per daxim's comment:</p>
  
  <pre><code>perl -MDevel::Peek -E'@a = (1..10); Dump each @a'
  
  SV = IV(0x161ce58) at 0x161ce68
    REFCNT = 1
    FLAGS = (TEMP,IOK,pIOK)
    IV = 0
  </code></pre>
  
  <p>however I have no idea what that tells me.</p>
  
  <p>Edit 3:</p>
  
  <p>It seems that the loop exits because the first index is <code>0</code>, or false. I have filed a bug ( <a href="http://rt.perl.org/rt3/Ticket/Display.html?id=90888" rel="nofollow">http://rt.perl.org/rt3/Ticket/Display.html?id=90888</a> ) since this doesn't seem to be the desired behavior. </p>