Re: function within qq{}
- From: Ben Morrow <ben@xxxxxxxxxxxx>
- Date: Tue, 2 Feb 2010 17:50:14 +0000
Quoth "Uri Guttman" <uri@xxxxxxxxxxxxxxx>:
"JB" == John Bokma <john@xxxxxxxxxxxxxxx> writes:
JB> cate <catebekensail@xxxxxxxxx> 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.
It's not a bug. \($x, $y, $z) is perfectly valid, and returns a list of
refs. (This also means that \(@a) is not the same as \@a: one of the few
cases where parens *are* necessary to denote a list.)
Ben
.
- Follow-Ups:
- Re: function within qq{}
- From: Uri Guttman
- Re: function within qq{}
- References:
- function within qq{}
- From: cate
- Re: function within qq{}
- From: John Bokma
- Re: function within qq{}
- From: Uri Guttman
- function within qq{}
- Prev by Date: Re: Want your opinion on @ARGV file globbing
- Next by Date: Re: function within qq{}
- Previous by thread: Re: function within qq{}
- Next by thread: Re: function within qq{}
- Index(es):
Relevant Pages
|