in reply to Sorting a subset
Try using grep, like so:
Update:You could also do it using substr instead of a regex. I'm not sure which on is more efficient.my @array = qw(Art bob joe andy willy Andrew john Archie); foreach(sort {substr($a,1) cmp substr($b,1)} grep /^A/, @array){ print "$_\n"; } __OUTPUT__ Andrew Archie Art
foreach(sort {substr($a,1) cmp substr($b,1)} grep {substr($_,0,1) eq ' +A'} @array)
- Tom
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Sorting a subset
by seaver (Pilgrim) on Dec 12, 2003 at 19:38 UTC | |
by BrowserUk (Patriarch) on Dec 12, 2003 at 19:55 UTC | |
by Not_a_Number (Prior) on Dec 12, 2003 at 20:04 UTC | |
by BrowserUk (Patriarch) on Dec 12, 2003 at 20:13 UTC | |
by tcf22 (Priest) on Dec 12, 2003 at 19:47 UTC | |
Re: Re: Sorting a subset
by Roy Johnson (Monsignor) on Dec 12, 2003 at 19:48 UTC |
In Section
Seekers of Perl Wisdom