Re: [code-review] Tie::Array::Sorted
Andy Lester <andy-U7RegYgSe6NWk0Htik3J/[email protected]> Wed, 12 Nov 2003 12:11:04 -0600
| Newsgroups | gmane.comp.lang.perl.code-review-ladder |
|---|---|
| Message-ID | <[email protected]> |
> > Just from a module-users point of view, I'm surprised to see the default
> > be a numerical sort rather than a string sort.
>
> Having a sorting module that, by default, sorted things differently from
> Perl's built-in sort for no good reason would be... suboptimal.
It's lexical by default, not numerical. From perldoc -f sort:
# sort lexically
@articles = sort @files;
# same thing, but with explicit sort routine
@articles = sort {$a cmp $b} @files;
$ cat foo.pl
#!/usr/bin/perl -lw
my @foo = ( 9, 15, 385, 2 );
print "Default: ", join( ", ", sort @foo );
print "cmp: ", join( ", ", sort { $a cmp $b } @foo );
print "<=>: ", join( ", ", sort { $a <=> $b } @foo );
$ perl foo.pl
Default: 15, 2, 385, 9
cmp: 15, 2, 385, 9
<=>: 2, 9, 15, 385
> You're more completist than I. ;)
Ayup. See also http://qa.perl.org/phalanx/
xoa
--
Andy Lester => andy-U7RegYgSe6NWk0Htik3J/[email protected] => www.petdance.com => AIM:petdance