in reply to sorting the column of array element
You're being unclear in what kind of data structure you are holding (try dumping it with Data::Dumper). However, I am guessing you have an array of arrayrefs.
The magic variables $a and $b in sort are aliases to the array's elements. Since the element is an arrayref, you need to dereference it. If you were to access the first column normally in your code, you'd say $array[$x]->[0]. Through the aliasing, $array[$x] is equal to $a or $b. Therefore, the correct syntax should be $a->[0]. So,
sort { $b->[0] <=> $a->[0] } @array
might do the trick.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sorting the column of array element
by sauoq (Abbot) on May 24, 2012 at 11:45 UTC | |
by anonym (Acolyte) on May 24, 2012 at 12:16 UTC | |
by sauoq (Abbot) on May 24, 2012 at 12:27 UTC |