in reply to How to get sort-like semantics?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to get sort-like semantics?
by friedo (Prior) on Oct 25, 2007 at 13:59 UTC | |
by duelafn (Parson) on Oct 26, 2007 at 19:55 UTC |