Groups | Search | Server Info | Login | Register
Groups > comp.lang.perl.misc > #4798
| From | Uri Guttman <uri@stemsystems.com> |
|---|---|
| Newsgroups | comp.lang.perl.misc |
| Subject | Re: Embedding code in qq{}? |
| Date | 2012-03-18 19:29 -0400 |
| Organization | albasani.net |
| Message-ID | <87limxtrn6.fsf@stemsystems.com> (permalink) |
| References | <87limyk471.fsf@Gmail.com> <jk41js$p48$1@reader1.panix.com> <1fjg39-qnv2.ln1@anubis.morrow.me.uk> <jk5nht$ot8$1@reader1.panix.com> |
>>>>> "TM" == Tim McDaniel <tmcd@panix.com> writes:
TM> In article <1fjg39-qnv2.ln1@anubis.morrow.me.uk>,
TM> Ben Morrow <ben@morrow.me.uk> wrote:
>>
>> Quoth tmcd@panix.com:
>>> In article <87limyk471.fsf@Gmail.com>, XeCycle <XeCycle@Gmail.com>
>>> wrote:
>>> >Is it possible to use something like "${1+2}" -> "3"?
>>>
>>> You made it clear in the rest of the article (which I trimmed) that
>>> you were thinking about the right-hand side of a s///. It turns out
>>> that, in string contexts in general, you can do it.
>>>
>>> Short answer:
>>> ${\(1+2)}
>>
>> If you must do this, then @{[...]} is clearer, since in both cases
>> the internal code is evaluated in list context.
TM> Both are in a scalar context, I think.
i know that to be wrong. one classic issue was that ${\bar()} always
calls in list context. there is no implicit way to get scalar context
there.
>>>>> "TM" == Tim McDaniel <tmcd@panix.com> writes:
TM> In article <1fjg39-qnv2.ln1@anubis.morrow.me.uk>,
TM> Ben Morrow <ben@morrow.me.uk> wrote:
>>
>> Quoth tmcd@panix.com:
>>> In article <87limyk471.fsf@Gmail.com>, XeCycle <XeCycle@Gmail.com>
>>> wrote:
>>> >Is it possible to use something like "${1+2}" -> "3"?
>>>
>>> You made it clear in the rest of the article (which I trimmed) that
>>> you were thinking about the right-hand side of a s///. It turns out
>>> that, in string contexts in general, you can do it.
>>>
>>> Short answer:
>>> ${\(1+2)}
>>
>> If you must do this, then @{[...]} is clearer, since in both cases
>> the internal code is evaluated in list context.
TM> Both are in a scalar context, I think.
TM> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TM> #! /usr/bin/perl
TM> use strict;
TM> use warnings;
TM> sub tester {
TM> if (wantarray) {
TM> print "array context\n";
TM> return [ 11, 12, 13 ];
TM> } else {
TM> print "scalar context\n";
TM> return \(22);
TM> }
TM> }
TM> print "scalar: ", ${tester()}, "\n";
TM> print "array: ", @{tester()}, "\n";
those are not correct tests. neither is being interpolated into a string
nor is \ being used. just a dereference in code will of course provide a
scalar context as you need a single scalar value to dereference.
change the code to "scalar: ${\tester()}\n" and "array: ${[tester()]}\n"
and see what happens. that is looking at the context in interpolation.
uri
Back to comp.lang.perl.misc | Previous | Next — Previous in thread | Next in thread | Find similar
Embedding code in qq{}? XeCycle <XeCycle@Gmail.com> - 2012-03-18 10:56 +0800
Re: Embedding code in qq{}? Uri Guttman <uri@stemsystems.com> - 2012-03-17 23:04 -0400
Re: Embedding code in qq{}? XeCycle <XeCycle@Gmail.com> - 2012-03-18 12:14 +0800
Re: Embedding code in qq{}? tmcd@panix.com (Tim McDaniel) - 2012-03-18 07:07 +0000
Re: Embedding code in qq{}? Ben Morrow <ben@morrow.me.uk> - 2012-03-18 08:37 +0000
Re: Embedding code in qq{}? tmcd@panix.com (Tim McDaniel) - 2012-03-18 22:28 +0000
Re: Embedding code in qq{}? merlyn@stonehenge.com (Randal L. Schwartz) - 2012-03-18 16:18 -0700
Re: Embedding code in qq{}? tmcd@panix.com (Tim McDaniel) - 2012-03-19 02:21 +0000
Re: Embedding code in qq{}? Uri Guttman <uri@stemsystems.com> - 2012-03-19 00:14 -0400
Re: Embedding code in qq{}? tmcd@panix.com (Tim McDaniel) - 2012-03-19 06:42 +0000
Re: Embedding code in qq{}? Ben Morrow <ben@morrow.me.uk> - 2012-03-19 16:40 +0000
Re: Embedding code in qq{}? Uri Guttman <uri@stemsystems.com> - 2012-03-18 19:29 -0400
Re: Embedding code in qq{}? Uri Guttman <uri@stemsystems.com> - 2012-03-18 15:24 -0400
Re: Embedding code in qq{}? tmcd@panix.com (Tim McDaniel) - 2012-03-18 22:33 +0000
Re: Embedding code in qq{}? Uri Guttman <uri@stemsystems.com> - 2012-03-18 19:24 -0400
Re: Embedding code in qq{}? Ben Morrow <ben@morrow.me.uk> - 2012-03-19 00:49 +0000
Re: Embedding code in qq{}? Uri Guttman <uri@stemsystems.com> - 2012-03-18 22:05 -0400
Re: Embedding code in qq{}? tmcd@panix.com (Tim McDaniel) - 2012-03-19 02:55 +0000
Re: Embedding code in qq{}? Uri Guttman <uri@stemsystems.com> - 2012-03-19 00:12 -0400
Re: Embedding code in qq{}? tmcd@panix.com (Tim McDaniel) - 2012-03-19 07:00 +0000
Re: Embedding code in qq{}? Ben Morrow <ben@morrow.me.uk> - 2012-03-19 16:43 +0000
csiph-web