sguazt has asked for the wisdom of the Perl Monks concerning the following question:
Hi!
I found out - :-( - that if you write a code like:
my @a = (1 .. 9); # for instance!! for my $e (@a) { $e += 1; }
you REALLY!! change the array element represented by $e.
So, to modify a copy you have to write:
my @a = (1 .. 9); # for instance!! for my $e (@a) { my $ee = $e # copy current element $ee += 1; }
Can anyone tell me if exists a shorter way or quicker solution to obtain what I want (i.e. to modify an array element) ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Modify array elements inside for loops
by MrNobo1024 (Hermit) on Mar 06, 2001 at 21:23 UTC | |
|
Re: Modify array elements inside for loops
by danger (Priest) on Mar 06, 2001 at 21:41 UTC | |
|
Re: Modify array elements inside for loops
by mirod (Canon) on Mar 06, 2001 at 21:27 UTC | |
|
Re: Modify array elements inside for loops
by arturo (Vicar) on Mar 06, 2001 at 21:34 UTC | |
by merlyn (Sage) on Mar 06, 2001 at 21:40 UTC | |
|
Re: Modify array elements inside for loops
by arhuman (Vicar) on Mar 06, 2001 at 21:17 UTC | |
by merlyn (Sage) on Mar 06, 2001 at 21:36 UTC | |
by arhuman (Vicar) on Mar 06, 2001 at 21:49 UTC |