in reply to How do I sort a Multidimensional array (not Hash)?

It works for me. You didn't provide a test case, so I had to write my own:

my @a = ( [4129290, 1675967, 2412031, '41%', '/usr/bin' ], [4129290, 1675967, 2412031, '41%', '/usr' ], [4129290, 1675967, 2412031, '41%', '/local' ], ); sorter(@a); __END__ output ====== before sort: /local Sorted by drive: /usr/bin

btw, you should use my in front of @beforeSort and @sorted_by_drive, and you'd probably be better off (due to smaller memory utilisation) to accept an array reference as an argument instead of an array, and returning an array reference, instead of the array.

Maybe you're not preparing the array properly? Here's an example:

my @df_k = split(/\n/, `df -k`); shift(@df_k); # Remove header. my @sorted_by_drive = sort { $a->[5] cmp $b->[5] } map { [ split(/\s+/, $_, 6) ] } @df_k; use Data::Dumper (); print(Data::Dumper->Dump( [ \@sorted_by_drive ], [qw( $sorted_by_drive )], ));

Updated reply to updated question:

1) Please please please please use use strict! You're not good enough to not use it yet.

2)

sub parseIntoArraySolaris (@df) ^^ what does this mean? It compiles, surprisingly, but it's not listed in docs and it doesn't give the args to the var @df.

3) Hold on, isn't [4] suppose to be a string? Why are you dividing a string by 1024? Similarly, [3] is a percentage, not an amount.

4) The function could use "some" improvement:

sub parseIntoArraySolaris { my @rows; my $element; foreach $element (@_) { my ($a, $b, $c, $d, $e, $f) = split(/\s+/, $element); push(@rows, [ $b/1024, $c/1024, $d/1024, $e, $f ]); } return @rows; }

which can be rewritten as:

sub parseIntoArraySolaris { return map { my ($a, $b, $c, $d, $e, $f) = split(/\s+/, $_); [ $b/1024, $c/1024, $d/1024, $e, $f ] } @_; }

and here's how it's used:

my @df_k = split(/\n/, `df -k`); shift(@df_k); # Remove header. my @beforeSort = parseIntoArraySolaris(@df_k); my @sorted_by_drive = sort { $a->[4] cmp $b->[4] } @beforeSort; use Data::Dumper (); print(Data::Dumper->Dump( [ \@sorted_by_drive ], [qw( $sorted_by_drive )], ));

wich can be rewritten as:

# Get data. my @df_k = split(/\n/, `df -k`); # Remove header. shift(@df_k); # Parse line. foreach (@df_k) { my ($a, $b, $c, $d, $e, $f) = split(/\s+/, $_); $_ = [ $b/1024, $c/1024, $d/1024, $e, $f ]; } # Sort. my @sorted_by_drive = sort { $a->[4] cmp $b->[4] } @df_k; # Quick way of printing for now. use Data::Dumper (); print(Data::Dumper->Dump( [ \@sorted_by_drive ], [qw( $sorted_by_drive )], ));