Groups | Search | Server Info | Login | Register
Groups > comp.lang.perl.misc > #4797
| From | Uri Guttman <uri@stemsystems.com> |
|---|---|
| Newsgroups | comp.lang.perl.misc |
| Subject | Re: Embedding code in qq{}? |
| Date | 2012-03-18 19:24 -0400 |
| Organization | albasani.net |
| Message-ID | <87pqc9trvt.fsf@stemsystems.com> (permalink) |
| References | <87limyk471.fsf@Gmail.com> <jk41js$p48$1@reader1.panix.com> <87ty1lu2z7.fsf@stemsystems.com> <jk5nsj$ot8$2@reader1.panix.com> |
>>>>> "TM" == Tim McDaniel <tmcd@panix.com> writes:
TM> In article <87ty1lu2z7.fsf@stemsystems.com>,
TM> Uri Guttman <uri@stemsystems.com> wrote:
>>>>>>> "TM" == Tim McDaniel <tmcd@panix.com> writes:
>>
TM> In article <87limyk471.fsf@Gmail.com>, XeCycle <XeCycle@Gmail.com>
TM> wrote:
>> >> Is it possible to use something like "${1+2}" -> "3"?
>>
TM> You made it clear in the rest of the article (which I trimmed)
TM> that you were thinking about the right-hand side of a s///. It
TM> turns out that, in string contexts in general, you can do it.
>>
TM> Short answer:
TM> ${\(1+2)}
>>
>> bad answer. first off it isn't needed as the /e modifier to s/// does
>> it.
TM> Which I tried to make clear but didn't. I wasn't trying to address
TM> the s/// case; everyone who pointed out s///e covered it quite nicely.
TM> I was trying to cover the case of being outside the RHS of s///.
but the OP was only really asking about s///. he conflated the
replacement part with a "" and was wrong there.
>> secondly it is a bad idea in general. the syntax for that is clunky
>> and hard to read. yes, it is legal and works. i just never do it nor
>> teach it to anyone. it is just poor coding IMNSHO.
TM> I see one use for it: @{[...]} interpolates a sub call into a quoted
TM> string, which you could not otherwise interpolate in a string. Since
TM> "use constant" makes the constant be a sub, that's also how you
TM> interpolate a "use constant" constant. (My work systems have Perl
TM> 5.8, and I have no control over the Perl version or the Perl stock of
TM> libraries, so I have to pretty much stick to stock Perl 5.8.)
it still is a poor construct to use. there is an Interpolate module that
does this with better syntax $() iirc. perl6 properly supports this idea
as well.
TM> It does help clarify for me what ${...} means, that ... is simply a
TM> block that returns a value.
${foo} is not such a thing. so your clarification is not totally
correct. the more i think about it, it isn't a true block in general. it is a
dereference operation that allows statements. you can't last out of it
(which you can from a bare block). so it is a limited type of block and
meant only for dereferencing. it will blow up if the last value is not
the proper ref type. a regular block need not return any value or if it
does (a do block, map block), it can return anything. there are some
serious differences so i wouldn't call it just a block.
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