in reply to Re: List-to-Scalar Function?
in thread List-to-Scalar Function?
(Stolen shamelessly from here, with full permission of the author. :-)sub reduce (&@) { my $op = shift; no strict 'refs'; my $pkg = caller; local *A = local *{"$pkg\::a"}; $A = shift; local *B = local *{"$pkg\::b"}; foreach $B (@_) { $A = $op->(); } $A; }
UPDATE
D'oh. I should have read the source-code. They don't
present that in the documentation... And I wrote it
originally because someone (jcwren I think) was having
trouble running my code at Re (tilly) 1: An exercise in "That's not the way I'd do it" (TNTWIDI) because
List::Util wasn't compiling.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re (tilly) 2: List-to-Scalar Function?
by merlyn (Sage) on May 09, 2001 at 03:55 UTC |