in reply to Loops in Perl
Yes, what you see on the left side of the equal sign is called an array slice. You can do something like this:
The code you posted is just the same idea.my @array = 0..5; my @ranks[@array] = 5..10; # @ranks now contains 5, 6, 7, 8, 9, 10
Update:
As noted by AnomalousMonk in the post just below, there is an error in the code above: it should be:We can't use "my" on an array with subscripts accessing to part of the array, the array must be declared before. I tested the code directly under the debugger, where it is not pôssible to use "my", and added the my on the line afterwards, creating erroneous code.my @array = 0..5; my @ranks; @ranks[@array] = 5..10; # @ranks now contains 5, 6, 7, 8, 9, 10
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Loops in Perl
by AnomalousMonk (Archbishop) on Mar 11, 2014 at 21:58 UTC | |
by Laurent_R (Canon) on Mar 12, 2014 at 19:00 UTC |