Hi monks, This is my first question since joining this site. Basically what I'm trying to do is grab the drivespace info in solaris, using df-k and try to compare this info to the same info, grabbed in another way. I am trying to sort this info that I just grabbed and then compare it later. I am having trouble with sorting it. I have a 2-dim array with scalars like:
4129290 1675967 2412031 41% /usr
The subroutine sorter is in a package and is called by the main program.
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; }
the 'print "before sort: ' gives a value of 2356 (I verified and it is a correct value)

The 'print "Sorted by drive:...." line prints nothing. The returned values are memory references but I found that I cannot refer to the data explicitly after sorting. UPDATE

Thanks for your replies, however, I did not explicitly create the 2-dim array. I used references to create the array when I read df-k information from Solaris:
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. }
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:...'.

In reply to How do I sort a Multidimensional array (not Hash)? by auyong

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.