in reply to Sorting an array of strings by number

Actually, you do not have to do the extra work of extracting the numbers from your strings if you do not want to. The way perl handles strings (IIRC) in a numeric context is it will take whatever it recognizes as a number off the front of the string, like in this example
print('1.01:dfsfda'+'1.34:kjlkljkj',"\n"); # prints 2.35\n
So, all you should need is the simple
@sorted = sort { $a <=> $b } @data;

                - Ant
                - Some of my best work - Fish Dinner

Replies are listed 'Best First'.
(tye)Re: Sorting an array of strings by number
by tye (Sage) on Oct 01, 2001 at 19:37 UTC

    True. But I don't think anyone has mentioned that this will generate warnings. But you can turn them off around that part of the code:

    my @sorted= do { local( $^W )= 0; sort { $a <=> $b } @data; };

            - tye (but my friends call me "Tye")

      Or if you're using a 5.6 or newer perl you can turn off just warnings about the numericness (see perllexwarn for more information).

      my @sorted = do { no warnings 'numeric'; sort { $a <=> $b } @data ; };
        Cheers guys, thats exactly what I needed to do.