auyong has asked for the wisdom of the Perl Monks concerning the following question:
The subroutine sorter is in a package and is called by the main program.4129290 1675967 2412031 41% /usr
the 'print "before sort: ' gives a value of 2356 (I verified and it is a correct value)sub sorter (@) { @beforeSort=@_; print "before sort: $beforeSort[2][4]\n"; @sorted_by_drive=sort{$a->[4] cmp $b->[4]} @beforeSort; print "Sorted by drive: $sorted_by_drive[2][4]\n"; return @sorted_by_drive; }
I think it works if you explicitly put the values into a multi-dim array, but when it is passed by reference, it may have some problem. I'm getting nothing outputted by the 'print "Sorted by drive:...'.sub parseIntoArraySolaris (@df) { $arrayCount=0; @rows; @col0; @col1; @col2; @col3; @col4; @col5; @col6; @col7; @col8; @col9; @col10; $rows[0]=\@col0; $rows[1]=\@col1; $rows[2]=\@col2; $rows[3]=\@col3; $rows[4]=\@col4; $rows[5]=\@col5; $rows[6]=\@col6; $rows[7]=\@col7; $rows[8]=\@col8; $rows[9]=\@col9; $rows[10]=\@col10; foreach $element (@_) { ($a, $b, $c, $d, $e, $f)=split(/\s+/,$element); #split +s strings separated by spaces,tabs ###################################################################### +################## #$rows[0][x] is just the column headings, Filesystem, kbytes, used, av +ail etc. #$rows[not zero][x] are the actual data. #for Windows, telnet cannot get the disk info, so we have to save the +info into a file, #use the FTP package to ftp (using ftppackage.pl package) the file to +the local system, #and use this 2-dim array to parse the data from the file. ###################################################################### +################## $rows[$arrayCount][0]=$b/1024; $rows[$arrayCount][1]=$c/1024; $rows[$arrayCount][2]=$d/1024; $rows[$arrayCount][3]=$e/1024; $rows[$arrayCount][4]=$f/1024; #$rows[$arrayCount][5]=$f; print "$rows[$arrayCount][0]\n"; print "$rows[$arrayCount][1]\n"; print "$rows[$arrayCount][2]\n"; print "$rows[$arrayCount][3]\n"; print "$rows[$arrayCount][4]\n"; #print "$rows[$arrayCount][5]\n"; ########################## To get to the value of the array, use $arra +y[$row][$column]; ########################## example: print "This is: $rows[$arrayCount] +[5]\n"; $arrayCount++; } return @rows; #returns the entire two-dimensional array. }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I sort a Multidimensional array (not Hash)?
by ikegami (Patriarch) on Sep 21, 2004 at 17:51 UTC | |
|
Re: How do I sort a Multidimensional array (not Hash)?
by tilly (Archbishop) on Sep 21, 2004 at 20:38 UTC | |
|
Re: How do I sort a Multidimensional array (not Hash)?
by bpphillips (Friar) on Sep 21, 2004 at 18:28 UTC | |
|
Re: How do I sort a Multidimensional array (not Hash)?
by auyong (Novice) on Sep 21, 2004 at 19:37 UTC |