Is the problem you are having in placing this function into a module? If that is the case, then the problem is getting ahold of the caller's $a and $b. Check out the code from reduce in List::Util.
sub reduce (&@) { my $code = shift; no strict 'refs'; return shift unless @_ > 1; use vars qw($a $b); my $caller = caller; local(*{$caller."::a"}) = \my $a; local(*{$caller."::b"}) = \my $b; $a = shift; foreach (@_) { $b = $_; $a = &{$code}(); } $a; }
Update: D'oh, a day late and a dollar short.
Good Day,
Dean
In reply to Re: How to get sort-like semantics?
by duelafn
in thread How to get sort-like semantics?
by b4swine
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |