in reply to How can we interpolate an expression??

Try the following:

use Modern::Perl; my $number = 5; my $multiplier = 3; say "Product is @{[$number * $multiplier]}";

Output:

Product is 15

Replies are listed 'Best First'.
Re^2: How can we interpolate an expression??
by Rohit Jain (Sexton) on Sep 20, 2012 at 18:33 UTC

    What I understand from this code is: -

    First we are converting the expression into an array or list.. Now, had we printed out that list or array, it would have printed out its address.. So, we have added an '@' before it to get an array.. Now, because we are not using a reference variable to this list, we have used a curly braces before using '@'

    Have I interpreted it correct.. Is this what happens in Perl?? Or can I get a better explanation of what is happening there?

      Great understanding!

      say "Product is @{[$number * $multiplier]}"; ^ ^ ^ ^ | | | | | | | + - EXPRESSION | | + - reference | + - dereference + - interpolate

        It's such a common combination of operations that it's even got a name: the baby cart.

        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'