bennymack has asked for the wisdom of the Perl Monks concerning the following question:
Hello, all
I was just bitten by some odd behavior so I decided I'd post it here and see if it's a bug, a gotcha, or a "Why are you doing that? Stop doing that!"
#!/usr/bin/env perl use strict; use warnings; my $aref = [ 'a' .. 'c' ]; warn 'ORIGINAL: $aref = ', join( q(, ), @{ $aref } ); for my $letter ( eval{ @{ $aref } } ) { $letter = 'z' . $letter; } warn 'NOT CHANGED: $aref = ', join( q(, ), @{ $aref } ); for my $letter ( @{ $aref } ) { $letter = 'z' . $letter; } warn 'CHANGED: $aref = ', join( q(, ), @{ $aref } );
What is happening or what it seems is happening is that when I loop through the elements of an array ref that was dereferenced inside of a block eval the assignment to the loop variable doesn't stick. I'm making no judgements one way or the other I'm just wondering what everyone else thinks of this. Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reassigning $_ in loop doesn't stick
by Limbic~Region (Chancellor) on Jan 21, 2009 at 20:58 UTC | |
|
Re: Reassigning $_ in loop doesn't stick
by kyle (Abbot) on Jan 21, 2009 at 21:01 UTC | |
by ikegami (Patriarch) on Jan 21, 2009 at 21:09 UTC | |
by Limbic~Region (Chancellor) on Jan 21, 2009 at 21:24 UTC | |
by kyle (Abbot) on Jan 21, 2009 at 21:31 UTC | |
by ikegami (Patriarch) on Jan 21, 2009 at 21:33 UTC | |
by Limbic~Region (Chancellor) on Jan 21, 2009 at 23:58 UTC | |
|