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.print "Sorted table...\n\n"; { no warnings 'numeric'; print sort { $a <=> $b } @table; }
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.
In reply to Re: sorting an array with mixed elements...
by Cristoforo
in thread sorting an array with mixed elements...
by cgmd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |