in reply to Numerically sorting array items containing delimited strings

Chimpmunk's answer does work since a string in perl that begins with a number will act like a number in numeric situations.
$str = "0.56HI There!"; $str += 10; # $str now is "10.56"
That will set off warnings though. (as well it should)
If you don't want to do a split, you can do this ugly piece of code.
sub bypre { substr($b,0,index($b,"+")) <=> substr($a,0,index($a,"+")); }
Update: Read Fastolfe's note and other people's suggestion of cmp

Replies are listed 'Best First'.
Re: Re: Numerically sorting array items containing delimited strings
by Fastolfe (Vicar) on Nov 30, 2000 at 00:30 UTC
    Note that this is very expensive, since you're doing an index and substr on each element of the list MANY TIMES in the course of doing your sort. You're better off going with a transformation like those in the above posts, which only do the expensive stuff once.