Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: perl v5.16 bug?

by tobyink (Abbot)
on Mar 15, 2013 at 23:38 UTC ( #1023795=note: print w/ replies, xml ) Need Help??


in reply to perl v5.16 bug?

The problem is that the entire while condition is evaluated every time around the loop, meaning that [@a] is evaluated every time around the loop, yielding a reference to a different anonymous array every time around the loop.

Because you're polling a fresh new array every time around the loop, each's "pointer" for the array is at the beginning every time.

This is the safe way to do it:

while (my ($i, $v) = each \@a) { say "$i: $v"; }

... because you're using a reference to the same array every time around the loop.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name


Comment on Re: perl v5.16 bug?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-12-21 21:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (108 votes), past polls