On Wed, Jan 19, 2005 at 04:59:33PM +, [EMAIL PROTECTED] wrote:
> Daisuke wrote:
> >
> > +sub _sort_positive_first
> > +{
> > +my @sorted = sort { $a <=> $b } @_;
> > +# put positive values first
> > +my @ret = grep { $_ >= 0 } @sorted;
> > +push @ret, $_ for grep { $_ < 0 } @sorted;
> > +
> > +return @ret;
> > +}
>
> I rewrote the sort:
>
> @args = sort {
> $a < 0 ? ( $b < 0 ? $a <=> $b : 1 ) :
>( $b < 0 ? -1 : $a <=> $b )
> } @args;
>
> DateTime::Event::Recurrence was uploaded to CPAN as
> version 0.15.
> I added a test for "modified parameter".
YMMV, but I find something like this more clear:
@args = sort { ($a < 0) <=> ($b < 0) || $a <=> $b } @args;
(literally, sort first by positive/negative, then by value).