Re: [MacPerl-AnyPerl] Sorting a list of alphanumeric strings

[email protected] (David Iberri) Fri, 24 Aug 2001 14:15:43 -0700 (PDT)
Newsgroups perl.macperl.anyperl
Message-ID <[email protected]>
This was my first guess, but I'm sure there are better
ways:

my @ary = qw(exon1
             exon5
             exon12
             exon30
             exon2);

@ary = sort by_exon_num @ary;

print join("\n", @ary), "\n";

sub by_exon_num {
	$a =~ /(\d+)/;
	my $a_dig = $1;
	$b =~ /(\d+)/;
	my $b_dig = $1;
	$a_dig <=> $b_dig;
}

HTH

Regards,
David

--- Adam Witney <[email protected]> wrote:
> Hi,
> 
> I am trying to sort a list like this
> 
> exon1
> exon5
> exon12
> exon30
> exon2
> 
> Into ->
> 
> exon1
> exon2
> exon5
> exon12
> exon30
> 
> Any ideas on how to do this?
> 
> Thanks
> 
> adam


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/