Path: csiph.com!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Uri Guttman Newsgroups: comp.lang.perl.misc Subject: Re: Embedding code in qq{}? Date: Sun, 18 Mar 2012 19:29:17 -0400 Organization: albasani.net Lines: 75 Message-ID: <87limxtrn6.fsf@stemsystems.com> References: <87limyk471.fsf@Gmail.com> <1fjg39-qnv2.ln1@anubis.morrow.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.albasani.net GWDEKxy3VFNe0TOvnOznFGt8W5YxiyO9+zV+7OvIDlnxE1ibu1txu3aw/Ht8PknLPxbf1VLzGn2poxt/PKW76VpdCf0jvmoReWQ4eD2sI9Eu7Oh4REC1LTKkzYGKcdnW NNTP-Posting-Date: Sun, 18 Mar 2012 23:30:00 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="66wpfw9oAX56iXQ3ZRj4oUgj5zDkTdnv5+j/C8kOp/o8DjroPwvDKyswgMxSBb+y1F7bvE4JvVduo/ngTyaImRjUslyEwg0deElbIcJ1s/wft4PXmzjfAgh817N9NzMo"; mail-complaints-to="abuse@albasani.net" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Cancel-Lock: sha1:4KWJGzUTj5BQu/4zb848UQMxT5I= sha1:cFE9p1iYhB0BUnUeC3L0LWCMbAI= Xref: csiph.com comp.lang.perl.misc:4798 >>>>> "TM" == Tim McDaniel writes: TM> In article <1fjg39-qnv2.ln1@anubis.morrow.me.uk>, TM> Ben Morrow wrote: >> >> Quoth tmcd@panix.com: >>> In article <87limyk471.fsf@Gmail.com>, XeCycle >>> 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 writes: TM> In article <1fjg39-qnv2.ln1@anubis.morrow.me.uk>, TM> Ben Morrow wrote: >> >> Quoth tmcd@panix.com: >>> In article <87limyk471.fsf@Gmail.com>, XeCycle >>> 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