in reply to How do I sort a Multidimensional array (not Hash)?
sub parseIntoArraySolaris { # this is what we'll return after we parse my @rows; foreach my $line(@_){ # here's a temporary array for each column's value # as we split it, we divide all the numbered # values by 1024 my @cols = map {m/^[\d.-]+$/ ? $_ / 1024 : $_} (split(/\s+/,$line))[0..5]; # just for debugging I'm assuming # see note below about using Data::Dumper print "$_\n" for(@cols); # add our parsed data for this line onto @rows # this is more idiomatic than how you were doing it # with the $arrayCount++ thing push(@rows,\@cols); } # now return all the data return @rows; } sub sorter { # this isn't very efficient for large arrays but # we're probably never doing very large data sets # for this problem my @rows = @_; # you might want to use Data::Dumper to do debugging # you just do a print "before sort: ".Dumper \@rows # and it'll give you a very nice dump of the data # structure print "before sort: $rows[2]->[4]\n"; my @sorted = sort{$a->[4] cmp $b->[4]} @rows; print "Sorted by drive: $sorted[2]->[4]\n"; return @sorted; }
|
|---|