>>>>> "BM" == Ben Morrow <> writes:
BM> Quoth "Uri Guttman" <>:
>> >>>>> "JB" == John Bokma <> writes:
>>
JB> cate <> writes:
>> >> I know you can do this, I just can't find it.
>> >> How do you call a sub within a qq{} construct
>> >>
>> >> qq{The common term for H2O is chem("H2O").}
>> >>
>> >> Thank you
>> >>
>> >> (As soon is this post is complete... I'll find it) 
>>
JB> perl -e '
JB> sub chem {
JB> my $term = shift;
JB> return "*$term*";
JB> }
JB> print qq{The common term for H2O is ${\( chem("H2O") ) }};
JB> '
>>
JB> use @{...} for list expressions, ${...} for scalar.
>>
>> partly incorrect.
>>
>> perl -le 'sub context {return "array" if wantarray} ; print "scalar
>> ${\context()}"'
>> scalar array
>>
>> that is an obscure bug that has been around a long time. the scalar form
>> still calls the sub in list context.
BM> It's not a bug. \($x, $y, $z) is perfectly valid, and returns a list of
BM> refs. (This also means that \(@a) is not the same as \@a: one of the few
BM> cases where parens *are* necessary to denote a list.)
yes, but the "${\foo()}" idiom looks like it will be in scalar
context. that is the issue. you need to put a scalar() in there. whether
it is a true bug or not, i say this is one reason to not use this
trick. using a variable is simpler, probably faster and safer.
uri
--
Uri Guttman ------
--------
http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ----
http://bestfriendscocoa.com ---------