imrags has asked for the wisdom of the Perl Monks concerning the following question:

I've an array of type
[["hello",4,"xyz","abc",6], ["hi",3,"xysfz","fdabc",4,"ewvd"], ["asyn",6,"xsdfyz","fweabc",3,"ensd","rew"], ];
i want an output similar to this:
[ ["hi",3,"xysfz","fdabc",4,"ewvd"], ["hello",4,"xyz","abc",6], ["asyn",6,"xsdfyz","fweabc",3,"ensd","rew"], ];

with Sorting to be done at the second column..
Any idea how to go about doing it??
Raghu

Replies are listed 'Best First'.
Re: Array of Arrays Sorting
by ccn (Vicar) on Dec 15, 2008 at 06:38 UTC
    my @sorted = sort {$a->[1] <=> $b->[1]} @$array;

    • perldoc -f sort
    • perldoc perlfaq4 (How-do-I-sort-an-array-by-(anything))
      Hi
      When I print sorted, I get this output
      ARRAY(0x19ff590)ARRAY(0x19ff650)ARRAY(0x1a00040)ARRAY(0x19ff860)ARRAY(0x19ff9b0)
      Raghu
Re: Array of Arrays Sorting
by imrags (Monk) on Dec 15, 2008 at 07:47 UTC
    Had to print them using
    foreach (@sorted) { print @$_; }
    That's it...thanks for solving the problem :)
    Raghu