in reply to Sorting issues

Your $one and $two are being compared as strings instead of numbers. This is because they both contain a '|' infront of the numbers.
my @sorted=sort{ my $one=substr($a,rindex($a,'|')); my $two=substr($b,rindex($b,'|')); $one =~ s/\D//g; $two =~ s/\D//g; ($one <=> $two) } @database;
This sorts it properly. I'm sure there's a better way to get at that last number, but I'm just stripping out anything that's not a digit.

HTH

Replies are listed 'Best First'.
Re: Re: Sorting issues
by merlyn (Sage) on May 27, 2001 at 18:17 UTC
    You really don't want to do this much work in the sort block, if the data size is significant. That's a good use for the Schwartzian Transform (or the GSR equivalent).

    -- Randal L. Schwartz, Perl hacker