in reply to Re: A generic sorting problem
in thread A generic sorting problem

Your first two examples would raise warnings galore when handling non numeric values, and the second example is simply an alphabetic sort, equivelent to sort @a

use warnings; use strict; my @a = qw( 2 two 1 11 12 one 3abcd 6foo ); print join( " ", sort { $a <=> $b || $a cmp $b } @a ), "\n"; __END__ Argument "two" isn't numeric in numeric comparison (<=>) at c:\temp\so +rt.pl line 4. Argument "one" isn't numeric in numeric comparison (<=>) at c:\temp\so +rt.pl line 4. Argument "3abcd" isn't numeric in numeric comparison (<=>) at c:\temp\ +sort.pl line 4. Argument "6foo" isn't numeric in numeric comparison (<=>) at c:\temp\s +ort.pl line 4. one two 1 2 3abcd 6foo 11 12
and
#... print join( " ", sort { $a cmp $b || $a <=> $b } @a ), "\n"; __END__ 1 11 12 2 3abcd 6foo one two

Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look.

Replies are listed 'Best First'.
Re: Re: Re: A generic sorting problem
by choocroot (Friar) on Jul 19, 2002 at 13:22 UTC
    Oops :( you are absolutely right !

    But is there a way to do this without getting the warnings messages ? by localizing $^W I guess ? or simply by not using this kind of construction :)))