Velocity Reviews > Perl > Data Dumper guidance

# Data Dumper guidance

Kasp
Guest
Posts: n/a

 11-13-2003
Hi Everyone,

Need some help in Data:umper.
What I want to do is sort this array (@arr) based on the first element of
the sub-arrays.
So I want finally is @sarr = ([3,2], [5,0], [6,3]);

Here is the code:
use Data:umper;
my @arr = ([5,0], [3,2], [6,3]);
print Data:umper->Dump(\@arr);
my @sarr = sort { \$a <=> \$b} @arr;
print Data:umper->Dump(\@sarr);

TIA
--

Andreas Kahari
Guest
Posts: n/a

 11-13-2003
In article <bova38\$1j5p2l\$(E-Mail Removed)-berlin.de>, Kasp wrote:
> Hi Everyone,
>
> Need some help in Data:umper.
> What I want to do is sort this array (@arr) based on the first element of
> the sub-arrays.
> So I want finally is @sarr = ([3,2], [5,0], [6,3]);

So, really this has nothing to do with Data:umper, but with
sorting.

> Here is the code:
> use Data:umper;
> my @arr = ([5,0], [3,2], [6,3]);
> print Data:umper->Dump(\@arr);
> my @sarr = sort { \$a <=> \$b} @arr;

That will sort on the array references in @arr.

You want this:
my @sarr = sort { \$a->[0] <=> \$b->[0]} @arr;

--
Andreas Kähäri

Kasp
Guest
Posts: n/a

 11-13-2003
> You want this:
> my @sarr = sort { \$a->[0] <=> \$b->[0]} @arr;

Thanks Andreas.

--