Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^2: How can we interpolate an expression??

by Rohit Jain (Sexton)
on Sep 20, 2012 at 18:14 UTC ( #994718=note: print w/replies, xml ) Need Help??

in reply to Re: How can we interpolate an expression??
in thread How can we interpolate an expression??

Can't we make your first "say ..." statement to print like the second one?? When we do this: -
say "number is $number";
It simply replaces the $number with its value.. Shouldn't it do the same for an expression.. or we have to do it in some different way?

Replies are listed 'Best First'.
Re^3: How can we interpolate an expression??
by kennethk (Abbot) on Sep 20, 2012 at 18:31 UTC
    If the interpreter implemented the interpolation you are specifying, then how could I as a programmer make it output the string Product is 5 * 3? There'd be some pretty non-intuitive side effects.

    Kenosis below has given you a way to be clever, but this is all getting a little clever for my taste. For complex output, I usually prefer going all the way to printf since, after all, you desire a formatted print. So maybe printf "number is %d\n", $number * $multiplier;. toolic's solution still strikes me as pretty clean as well.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      Yeah it's right that its not worth making simple thing complex.. But just wanted to know whether there is a way to do it. Just for the sake of knowing. Anyways I am going to use the other way.

      And what you are saying about that printf, I haven't reached there, so didn't knew that also existed in Perl. Will sure be interesting to use that.. For now, I am using concatenation using '.' or ','

      Thanks Anyways :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994718]
[perldigious]: If you want a linguistic adventure...
[perldigious]: No offense to any Scotsman, I love Scots. Well actually, I love Scotch, but I'm sure the people are great too. :-P
[Discipulus]: perldigious i understand i word on ten, to be optimistic..
LanX will try to give his next LPW talk with a Cogney intonation
[Discipulus]: if you love Scotch in scotland your safety will be.. glengranted
[LanX]: *Cockney

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-06-23 16:50 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (552 votes). Check out past polls.