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:

my @array = 0..5; my @ranks[@array] = 5..10; # @ranks now contains 5, 6, 7, 8, 9, 10
The code you posted is just the same idea.

Update:

As noted by AnomalousMonk in the post just below, there is an error in the code above: it should be:
my @array = 0..5; my @ranks; @ranks[@array] = 5..10; # @ranks now contains 5, 6, 7, 8, 9, 10
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.

Replies are listed 'Best First'.
Re^2: Loops in Perl
by AnomalousMonk (Archbishop) on Mar 11, 2014 at 21:58 UTC

    my @ranks[@array] = 5..10; is a syntax error.

    c:\@Work\Perl>perl -wMstrict -MData::Dump -le "my @array = 0..5; my @ranks; @ranks[@array] = 5..10; dd \@ranks; " [5 .. 10]

    Update: However, the following works for initializing a new lexical (reverse used just to add some variety):

    c:\@Work\Perl>perl -wMstrict -MData::Dump -le "my @array = reverse 0 .. 5; my @ranks = (5 .. 10)[@array]; dd \@ranks; " [10, 9, 8, 7, 6, 5]
      Thank you for your comment, AnomalousMonk, you are right. I added the "my" after having tested and that was a mistake. I have updated my post accordingly.