Instead of running perl with the -w switch, use warnings; and turn off the particular warning in a scope. That needs Perl 5.6+.
$ perl -Mwarnings -MData::Dumper -e ' > @old = ( "10.5 AA", "9 AC", "2 BB"); > @new = do {no warnings q/numeric/; sort {$b <=> $a} @old}; > print Dumper \@new;' $VAR1 = [ '10.5 AA', '9 AC', '2 BB' ]; $
(Added) If you're in pre-5.6 perl, or you just want to do it this way, this works:
That knocks out all warnings in the scope.$ perl -w -MData::Dumper -e ' > @old = ( "10.5 AA", "9 AC", "2 BB"); > @new = do {local $^W = 0; sort {$b <=> $a} @old}; > print Dumper \@new;' $VAR1 = [ '10.5 AA', '9 AC', '2 BB' ]; $
After Compline,
Zaxo
In reply to Re: Numeric Sort for Stringified Value (How to Avoid Warning)
by Zaxo
in thread Numeric Sort for Stringified Value (How to Avoid Warning)
by neversaint
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |