logo       

Re: sort with special order: msg#00350

perl-beginners

Subject: Re: sort with special order

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 strict;
use warnings;

my @list = map { qw(dog is a there)[$_]; } qw(3 1 2 0);
print "@list";

... or all at once:

print join(' ', my @list = map { qw(dog is a there)[$_]; } qw(3 1 2 0));

:) Steve

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Google Custom Search

News | Mail Home | sitemap | FAQ | advertise