Re: sort with special order

2009-07-24 Thread Chas. Owens
On Fri, Jul 24, 2009 at 11:01, Jo for lists and groups wrote: > How about this? Jo > > > > #!/usr/bin/perl > > use strict; > use warnings; > > my @list = qw/dog is a there/; > my @sortOrder = (3,1,2,0); > my @sorted; > foreach (@sortOrder) { push(@sorted,$list[$_]); } > > print "@sorted"; > exit; s

Re: sort with special order

2009-07-24 Thread Steve Bertrand
Steve Bertrand wrote: > Jo for lists and groups wrote: >> How about this? Jo > >> #!/usr/bin/perl >> >> use strict; >> use warnings; >> >> my @list = qw/dog is a there/; >> my @sortOrder = (3,1,2,0); >> my @sorted; >> foreach (@sortOrder) { push(@sorted,$list[$_]); } >> >> print "@sorted"; >> exit

Re: sort with special order

2009-07-24 Thread Steve Bertrand
Jo for lists and groups wrote: > How about this? Jo > #!/usr/bin/perl > > use strict; > use warnings; > > my @list = qw/dog is a there/; > my @sortOrder = (3,1,2,0); > my @sorted; > foreach (@sortOrder) { push(@sorted,$list[$_]); } > > print "@sorted"; > exit; ...or this: #!/usr/bin/perl use

RE: sort with special order

2009-07-24 Thread Jo for lists and groups
How about this? Jo #!/usr/bin/perl use strict; use warnings; my @list = qw/dog is a there/; my @sortOrder = (3,1,2,0); my @sorted; foreach (@sortOrder) { push(@sorted,$list[$_]); } print "@sorted"; exit; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands

Re: sort with special order

2009-07-23 Thread Chas. Owens
On Fri, Jul 24, 2009 at 00:14, sys adm wrote: > Hi, > > When I got a word list, I want it to be sorted with special order. > for example, I got this array: > > ("dog","is","a","there"); > > I want the sorted result is: > > ("there","is","a","dog"); > > How to code it? Thank you. snip You need to s

sort with special order

2009-07-23 Thread sys adm
Hi, When I got a word list, I want it to be sorted with special order. for example, I got this array: ("dog","is","a","there"); I want the sorted result is: ("there","is","a","dog"); How to code it? Thank you. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands,

Re: sort with special order

2005-10-03 Thread Jeff 'japhy' Pinyan
[sorry, PINE has become very confused about who said what] On Oct 3, Jay Savage said: On 10/3/05, Bakken, Luke <[EMAIL PROTECTED]> wrote: JupiterHost.Net wrote: >> On Oct 3, JupiterHost.Net said: >> >>> I have a list of strings that start with an uppercase B, Q, or Z >>> >>> I need to sort them

Re: sort with special order

2005-10-03 Thread John W. Krahn
Bakken, Luke wrote: > JupiterHost.Net wrote: >>>On Oct 3, JupiterHost.Net said: >>> I have a list of strings that start with an uppercase B, Q, or Z I need to sort them so they are in order of Q, B , then Z Any ideas or input on how to efficiently do that with sort() or even >

Re: sort with special order

2005-10-03 Thread Jay Savage
On 10/3/05, Bakken, Luke <[EMAIL PROTECTED]> wrote: > JupiterHost.Net wrote: > >> On Oct 3, JupiterHost.Net said: > >> > >>> I have a list of strings that start with an uppercase B, Q, or Z > >>> > >>> I need to sort them so they are in order of Q, B , then Z > >>> > >>> Any ideas or input on how t

RE: sort with special order

2005-10-03 Thread Bakken, Luke
JupiterHost.Net wrote: >> On Oct 3, JupiterHost.Net said: >> >>> I have a list of strings that start with an uppercase B, Q, or Z >>> >>> I need to sort them so they are in order of Q, B , then Z >>> >>> Any ideas or input on how to efficiently do that with sort() or even >>> map() is most appre

Re: [SPAM DETECT] Re: sort with special order

2005-10-03 Thread Jeff 'japhy' Pinyan
On Oct 3, Xavier Noria said: On Oct 3, 2005, at 18:16, Jeff 'japhy' Pinyan wrote: my @sorted = map { tr/123/QBZ/; $_ } sort map { tr/QBZ/123/; $_ } @data; There's a potential gotcha there: since all Qs and Bs are being swapped lexicographic order after the first character

Re: sort with special order

2005-10-03 Thread JupiterHost.Net
On Oct 3, JupiterHost.Net said: I have a list of strings that start with an uppercase B, Q, or Z I need to sort them so they are in order of Q, B , then Z Any ideas or input on how to efficiently do that with sort() or even map() is most appreciated :) perldoc -f sort|-f map didn't appear to

Re: [SPAM DETECT] Re: sort with special order

2005-10-03 Thread Xavier Noria
On Oct 3, 2005, at 18:16, Jeff 'japhy' Pinyan wrote: On Oct 3, JupiterHost.Net said: I have a list of strings that start with an uppercase B, Q, or Z I need to sort them so they are in order of Q, B , then Z Any ideas or input on how to efficiently do that with sort() or even map() is mos

Re: sort with special order

2005-10-03 Thread Jeff 'japhy' Pinyan
On Oct 3, JupiterHost.Net said: I have a list of strings that start with an uppercase B, Q, or Z I need to sort them so they are in order of Q, B , then Z Any ideas or input on how to efficiently do that with sort() or even map() is most appreciated :) perldoc -f sort|-f map didn't appear to

Re: sort with special order

2005-10-03 Thread Xavier Noria
On Oct 3, 2005, at 17:35, JupiterHost.Net wrote: I need to sort them so they are in order of Q, B , then Z The real array will have between 1 to 100 items, just FYI They all go in ASCII relative order except B <-> Q, thus a way to get it is to handle that special case and delegate to cmp

sort with special order

2005-10-03 Thread JupiterHost.Net
Howdy List :) I have a list of strings that start with an uppercase B, Q, or Z I need to sort them so they are in order of Q, B , then Z my @sample_strings = qw(Bang Quiet Zing Zop Quid Boo); I need them to be sorted as: Quid Quiet Bang Boo Zing Zop I'd like to sort() them but can't f