This should not matter what the size is but would expect a number at
the beginning:
foreach my $MyKey (sort {$a->[1] <=> $b->[1]}
map{[ $_, /^(\d+)/ ]}
keys %final_list) {
printf "%-s\n", $MyKey->[0];
}
Wags ;)
-----Original Message-----
From: John W. Krahn [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 24, 2002 13:54
To: [EMAIL PROTECTED]
Subject: Re: another sort question (flame away)
Nkuipers wrote:
>
> Hello all,
Hello,
> My hash keys look something like this:
>
> >1234 x5
>
> So I am thinking a cmp, as opposed to <=> is best.
>
> What I want is for the keys to be sorted as follows:
>
> >1 x....
> >2 x....
> >3 x....
> ..
> ..
> ..
> >n x....
>
> This is what I have in my script at the moment:
>
> my @sort_this = keys %final_list;
> my @sorted = sort { $a cmp $b } @sort_this;
> for (@sorted) { print OUT "$_\n$final_list{$_}\n" }
>
> This gives
>
> >1 x....
> >10 x....
> >100 x....
> >1000 x....
> >1001 x....
>
> etc.
>
> Any suggestions? I'm not asking for you to spell it out for me with code
and
> all unless you really want to. Sorry if this is a dumb question.
This should work, assuming the digits at the start of the key are no
longer then 10.
my @sorted = map { /\0(.+)/ }
sort
map { sprintf "%010d%s\0%s", /(\d+)(.+)/, $_ }
keys %final_list;
print OUT "$_\n$final_list{$_}\n" for @sorted;
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]