dda has asked for the wisdom of the Perl Monks concerning the following question:
The following code changes contents of array @a:
Which is the best (most effective) way to make sure that no code inside the loop will modify array contents? I'm looking for a way to make the list not to be assignable.use strict; use Data::Dumper; my @a = qw(1 2 3); print Dumper(\@a); for my $b (@a) { $b *= 2; } print Dumper(\@a);
--dda
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Preserve array contents in for() loop
by dragonchild (Archbishop) on Sep 21, 2004 at 12:31 UTC | |
by dda (Friar) on Sep 21, 2004 at 13:06 UTC | |
by dragonchild (Archbishop) on Sep 21, 2004 at 13:53 UTC | |
|
Re: Preserve array contents in for() loop
by Roy Johnson (Monsignor) on Sep 21, 2004 at 14:11 UTC | |
|
Re: Preserve array contents in for() loop
by punkish (Priest) on Sep 21, 2004 at 14:48 UTC | |
by davido (Cardinal) on Sep 21, 2004 at 15:12 UTC | |
by punkish (Priest) on Sep 21, 2004 at 15:24 UTC |