in reply to Re: Sorting array with multiple values per keys
in thread Sorting array with multiple values per keys

Thanks for the great reply, guys. I chose to use this as a solution:
my @Array = ( [1, 5], [6, 2], [3, 4], [3, 9], [8, 1], ); @Array = sort { $a->[0] <=> $b->[0] or $b->[1] <=> $a->[1] } @Array;
It works great but how do I call the first element of the first element in the @Array now? Something like @Array[0]->[0] ? And can I still use foreach operators now? Like:
foreach @Elements (@Array) { print @Elements[0]."x".@Elements[1]; }

Replies are listed 'Best First'.
Re^3: Sorting array with multiple values per keys
by ikegami (Patriarch) on Aug 13, 2008 at 01:21 UTC

    Like I already said,
    @Array[0]
    is inappropriate and produces a warning. Use
    $Array[0]->[0]
    or
    $Array[0][0]
    for short.

Re^3: Sorting array with multiple values per keys
by betterworld (Curate) on Aug 13, 2008 at 01:41 UTC
    foreach $Elements (@Array) { print $Elements->[0] . 'x' . $Elements->[1]; }
    Loop variables in foreach loops must be scalars, but scalars can be array references.