> > $sum = reduce {$_[0]+$_[1]} 0, @numbers || die "Chaos!!";
>
> >Note with the || that way, it'll die immediately if @numbers is empty,
> >even before destroying the universe.
>
> Yes, but why are you passing the size of the array in there?
:-)
And even if you wrote:
$sum = reduce(^_+^_, @numbers) || die "Chaos!!";
you're still going to over-react to a zero-sum sequence.
You need:
defined($sum = reduce ^_+^_, @numbers) || die "Chaos!!";
Damian
- Re: RFC 76 (v2) Builtin: reduce Damian Conway
- Re: RFC 76 (v2) Builtin: reduce Damian Conway
- Re: RFC 76 (v2) Builtin: reduce Graham Barr
- Re: RFC 76 (v2) Builtin: reduce iain truskett
- Re: RFC 76 (v2) Builtin: reduce John Porter
- Re: RFC 76 (v2) Builtin: reduce Nathan Wiger
- Re: RFC 76 (v2) Builtin: reduce Tom Christiansen
- Re: RFC 76 (v2) Builtin: reduce Nathan Wiger
- Re: RFC 76 (v2) Builtin: reduce Randal L. Schwartz
- Re: RFC 76 (v2) Builtin: reduce Damian Conway
- Re: RFC 76 (v2) Builtin: reduce Damian Conway
- Re: RFC 76 (v2) Builtin: reduce Tom Christiansen
- Re: RFC 76 (v2) Builtin: reduce Graham Barr
- Re: RFC 76 (v2) Builtin: reduce Nathan Wiger
- Re: RFC 76 (v2) Builtin: reduce Peter Scott
- Re: RFC 76 (v2) Builtin: reduce Tom Christiansen
- Re: RFC 76 (v2) Builtin: reduce Damien Neil
- Re: RFC 76 (v2) Builtin: reduce John Porter
- Re: RFC 76 (v2) Builtin: reduce Glenn Linderman
- Re: RFC 76 (v2) Builtin: redu... John Porter
- Re: RFC 76 (v2) Builtin: reduce Damian Conway
