in reply to Re: Loops in Perl
in thread Loops in Perl

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]

Replies are listed 'Best First'.
Re^3: Loops in Perl
by Laurent_R (Canon) on Mar 12, 2014 at 19:00 UTC
    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.