in reply to sorting an array with mixed elements...

Or, to simplify the sort, the code could be...
print "Sorted table...\n\n"; { no warnings 'numeric'; print sort { $a <=> $b } @table; }
Perl will sort numerically if the leading characters are 0-9 and issue a warning if the remaining characters are not numeric, as in this example. Warnings in this block are temporarlily turned off.
Chris

Update: playing around with the above code, I discovered that if I put another print sort { $a <=> $b } @table; following the block, warnings weren't given, even though I believed they should be - after all, that was the reason for putting the no warnings... code in its own scope (block).
If I commented out the call to print in the enclosed block, then warnings were given for the call to print following the block.

Update2: Warnings indeed do come back on (if a second list, @list2, also of mixed alphanumeric values) is sorted following the block.

Replies are listed 'Best First'.
Re^2: sorting an array with mixed elements...
by cgmd (Beadle) on Jun 10, 2007 at 12:31 UTC
    To use the method proposed by Cris...
    print "Sorted table...\n\n"; { no warnings 'numeric'; print sort { $a <=> $b } @table; }
    ...when each element starts with an alphabetic character, and an alphabetic sort is desired (targeting each element's initial alpha character) this would,presumably, then become:
    print "Sorted table...\n\n"; { # no warnings 'numeric'; print sort { $a cmp $b } @table; }
    Is a "no warnings" statement also warranted?

    Thanks!

      print sort { $a cmp $b } @table;

      That is the default and you'd better not specify it at all.

      Is a "no warnings" statement also warranted?

      No except perhaps if any element of @table is undef and you want it to be and perl not to complain. Do you?

        blazar wrote:

        "That is the default and you'd better not specify it at all."

        Thanks, for that information!