in reply to RE: RE: scalarmap - some new perl syntax
in thread scalarmap - some new perl syntax
How so? Your initial value is, in this case, really just the first element of the array, in the case of reduce (I didn't realize this until looking at reduce, granted). So you'd just make your array 1..$N for a factorial. Like this:> It calls your sub with $a and $b set to the first two > elements of the array which is neater in some ways, > but would make it harder to write the factorial example > above.
sub factorial { reduce { $a * $b } 1..$_[0] }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: RE: RE: scalarmap - some new perl syntax
by ncw (Friar) on Sep 01, 2000 at 12:01 UTC |