function within qq{}

P

Peter Scott

c> @{[mysub(1,2,3)]}
c> good grief. Thanks

and that is considered a poor construct. i never use it (or its scalar
cousin) nor do i recommend it. when i review code, i downgrade when i
see that used. it is simpler and better to just assign to a variable
before the string and then interpolate it. also it will likely be faster
as you don't need the reference/dereference. also it will only call your
code in a list context (even the scalar form!) which may be a problem.
assigning to your own variable allows you to control the context as
well.

There is always MJD's Evaluation module (looks like Jenda's expanded on
it some); elegant in execution, a bit heavyweight in the setup, but worth
knowing:

use Evaluation E => 'eval';
qq[The common term for H2O is $E{ chem("H2O") }.]
 
T

Ted Zlatanov

On Thu, 04 Feb 2010 07:51:45 -0800 (e-mail address removed) wrote:

This is just for example purposes. Should you need a full
blown formatter, there are probably dozens of safe ones on
Cpan.

my $evstr = "\$retval = sprintf ($msg, ". "@{[map {qq(\"$_\",)} @data]}" .");";
s> Shorter:
s> my $evstr = "\$retval = sprintf ($msg, @{[map {qq(\"$_\",)} @data]} );";
s> or
s> my $evstr = "\$retval = sprintf ($msg, @{[map {qq('$_',)} @data]} );";
s> You lost me. Something wrong with this?
s> Whats a better way?

I'm saying you improved it a little but the whole thing is a
Frankenstein monster. I wasn't criticizing your change per se.

Ted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top