in reply to Re^3: Create reference to sorted anonymous array
in thread Create reference to sorted anonymous array
I haven't tested it yet whether this also works:for($i = $#sizes; $i >= 0 ; --$i) { print $sizes[$i]; }
Yes, you could do instead:for(my $i = 0; $i <= #$arrayref; $i+=2) { print "$i: $arrayref->[$i]\n"; }
But here you have to be aware that $i is incremented by 1 by the loop itself and then again by 1 through $i++. Makes it a bit more difficult to read imho.for my $i (0 .. $#$arrayref) { print "$i: $arrayref->[$i]\n"; $i++; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Create reference to sorted anonymous array
by AnomalousMonk (Archbishop) on Mar 18, 2016 at 12:08 UTC | |
by Digioso (Sexton) on Mar 18, 2016 at 12:30 UTC | |
by Your Mother (Archbishop) on Mar 18, 2016 at 13:24 UTC |