in reply to sorting an array with mixed elements...
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sorting an array with mixed elements...
by cgmd (Beadle) on Jun 10, 2007 at 12:31 UTC | |
by blazar (Canon) on Jun 10, 2007 at 21:27 UTC | |
by cgmd (Beadle) on Jun 10, 2007 at 22:22 UTC |