Hail fellow monks, It seems that I need to come for your sage advice once again. I have a record that I read into a bunch of arrays.
(@array1, @array2, @array3, ...)= split;
Now $array1[0] and $array2[0] and $array3[0] and ... all reference different fields in the same record. The fields vary as to type and length. What I need to do is sort any one of the fields and then display all fields associated with that sorted field. I thought that I could create an index with the following code, but it doesn't seem to work that way. Also, not all the fields are unique, so how do you allow for double records in the sorted file and still keep them associated with the same record in the unsorted file.
sub Sort_File { my @Sort_by = @_; @sorted_array = sort { $a <=> $b || $a cmp $b } Sort_by; for ($x = 0; $x <= @sorted_array; $x++){ for ($y = 0; $y <= @sorted_array; $y++){ if ( $sorted_array[$x] == $Sort_by[$y]) { $index[$x] = $y; print $index[$x],"\n"; } } }
Thanks in advance! Prince99

Too Much is never enough...

In reply to Sorting arrays and maintaining an index by Prince99

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.