Problem with Interpolation

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

The manpage of Interpolation says:

   It is posible to pass multiple (or no) arguments to your function.
   There are two alternate syntaxes:


   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\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 @_;

Unfortunately I get:
   print "sum is $sum\n";
   *** 41
   sum is

Is this normal behavior?
Jean-Louis Leroy

Re: Problem with Interpolation

Quoted text here. Click to load it

Quoted text here. Click to load it

I guess this is not the "quite some magic".

I read quickly the documentation, and guess:

  'foo:$*->$   - ask for arbitrary number of scalar parameters

with "NOT required anymore."

use Interpolation 'sum:$*->$' => sub {

    print "*** @_\n";
    my $sum = 0;
    $sum += $_ for @_;

    return $sum;

should work I guess.

John Bokma          Freelance software developer
                    Experienced Perl programmer:

Site Timeline