snafu has asked for the wisdom of the Perl Monks concerning the following question:
All of that is in an array (by line, of course). I need to sort it by the number in the first field delimited by the '!' without actually affecting the elements in the original array.100!100!key!date!2.. 100!100!key!store! 110!110!P\d\d\d_.*\.\d{6,}\.EMRemr 120!125! 1!yeada 130!132! 140!133! 150!134! 500!blah 160!135!arbor_ama 503!blah 170!136! 505!blah 180!137! 190!138!
I don't know *why* I can't think my way through this. Here is what I have tried:
Which sorts great but it alters the elements in the original array such that all I get returned is the first field delimited by '!'.my @array = (all that stuff above); @array = map { $_[0] = (split(/\!/,$_))[0]; } sort { $a <=> $b; } @array;
The above code returns:
1 100 100 110 120 130 140 150 160 170 180 190 500 503 505
when what I need is:
1 100!100!key!date!2.. 100!100!key!store! 110!110!P\d\d\d_.*\.\d{6,}\.EMRemr 120!125! 130!132! 140!133! 150!134! 160!135!arbor_ama 170!136! 180!137! 190!138! 500!blah 503!blah 505!blah
I know I am missing something. What is it? :) sort{} is still a challenge to me sometimes.
TIA guys!
_
_
_
_
_
_
_
_
_
_
- Jim
Insert clever comment here...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sort based on a delimited field in array elements without affecting original array elements
by Kanji (Parson) on Mar 01, 2002 at 23:14 UTC | |
by tadman (Prior) on Mar 01, 2002 at 23:36 UTC | |
by I0 (Priest) on Mar 01, 2002 at 23:47 UTC | |
|
•Re: Sort based on a delimited field in array elements without affecting original array elements
by merlyn (Sage) on Mar 01, 2002 at 23:46 UTC | |
|
Re: Sort based on a delimited field in array elements without affecting original array elements
by patgas (Friar) on Mar 01, 2002 at 23:14 UTC | |
|
Re: Sort based on a delimited field in array elements without affecting original array elements
by VSarkiss (Monsignor) on Mar 01, 2002 at 23:09 UTC |