awohld has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use Data::Dumper; my $array = []; push @$array, [ '1', 'one' ]; push @$array, [ '8', 'eight' ]; push @$array, [ '2', 'two' ]; push @$array, [ '100', 'one hundred' ]; push @$array, [ '4', 'four' ]; push @$array, [ '67', 'sixty seven' ]; my $array2 = sort { $@a->[0] <=> $@b->[0] } @$array; print Dumper \$array2;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sort Array Reference by Numeric First Element
by japhy (Canon) on Jun 11, 2006 at 05:22 UTC | |
|
Re: Sort Array Reference by Numeric First Element
by liverpole (Monsignor) on Jun 11, 2006 at 05:23 UTC | |
|
Re: Sort Array Reference by Numeric First Element
by sh1tn (Priest) on Jun 11, 2006 at 07:56 UTC | |
|
Re: Sort Array Reference by Numeric First Element
by planetscape (Chancellor) on Jun 11, 2006 at 20:00 UTC |