On 8/14/07, Wagner, David --- Senior Programmer Analyst --- WGO
<[EMAIL PROTECTED]> wrote:
> I am attempting to sort data which has a combination of both numeric
> and alpah numeric data. Now it would not be so bad, but the numeric data
> can be either 9 or 10 characters in length and no leading zero is
> supplied in the numbers.
>
> I have supplied some code I am playing with, but running into a mental
> block in attempting to get it sorted.
>
> Any thoughts on how to approach would be greatly appreciated?
snip
untested:
@sorted_data = sort &compare @data;
sub compare {
#assumes we are using ints
my $anum = $a =~ /^\s*\d+\s*$/;
my $bnum = $b =~ /^\s*\d+\s*$/;
return $a <=> $b if $anum and $bnum;
return $a cmp $b;
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/