in reply to Create reference to sorted anonymous array
C style for() loops are actually quite rare in Perl. They are prone to the dreaded and most common programming error, the "off by one error". Here is another way to write blubb().
use strict; use warnings; sub blubb { my $array_ref = shift; my $i =0; foreach (@$array_ref) #dereferences the ref to an array { print $i++, " $_\n"; } } my @array = (1, 2, 3); blubb([reverse @array]); __END__ Prints: 0 3 1 2 2 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Create reference to sorted anonymous array
by Digioso (Sexton) on Mar 17, 2016 at 13:42 UTC | |
by choroba (Cardinal) on Mar 17, 2016 at 17:01 UTC | |
by AnomalousMonk (Archbishop) on Mar 17, 2016 at 18:45 UTC | |
by Digioso (Sexton) on Mar 18, 2016 at 09:40 UTC | |
by AnomalousMonk (Archbishop) on Mar 18, 2016 at 12:08 UTC | |
by Digioso (Sexton) on Mar 18, 2016 at 12:30 UTC | |
| |
by Marshall (Canon) on Mar 18, 2016 at 21:40 UTC |