Problem with Interpolation
am 08.08.2006 13:52:45 von Jean-Louis LeroyThe manpage of Interpolation says:
It is posible to pass multiple (or no) arguments to your function.
There are two alternate syntaxes:
$interpolator{param1,param2}
$interpolator{param1}{param2}
The first syntax will pass both arguments in $_[0] joined by $;, so you
have to split them:
use Interpolation add => sub{@_ = split /$;/o, $_[0]; $_[0] + $_[1]};
print "3 + 4 = $add{3,4}\n";
The other syntax (used for example by builtin 'sprintf') requires quite
some magic, so you probably wouldn't want to be forced to write it
yourself. (See the source of this module if you want to know how
strange is the code. )
I try the second syntax, hoping to get all the arguments in @_:
use Interpolation sum => sub {
print "*** @_\n";
my $sum = 0;
$sum += $_ for @_;
$sum
};
Unfortunately I get:
print "sum is $sum{41}{2}{3}\n";
*** 41
sum is
Is this normal behavior?
--
Jean-Louis Leroy
Europerl
http://www.europerl.be