Prince99 has asked for the wisdom of the Perl Monks concerning the following question:
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.(@array1, @array2, @array3, ...)= split;
Thanks in advance! Prince99sub 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"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorting arrays and maintaining an index
by Masem (Monsignor) on Apr 12, 2001 at 21:21 UTC | |
|
Re: Sorting arrays and maintaining an index
by suaveant (Parson) on Apr 12, 2001 at 21:29 UTC | |
|
Re: Sorting arrays and maintaining an index
by satchboost (Scribe) on Apr 12, 2001 at 21:28 UTC | |
by Prince99 (Scribe) on Apr 12, 2001 at 22:07 UTC |