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:24:06 -0400 Organization: albasani.net Lines: 56 Message-ID: <87pqc9trvt.fsf@stemsystems.com> References: <87limyk471.fsf@Gmail.com> <87ty1lu2z7.fsf@stemsystems.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.albasani.net C6+k+HYC0qv7faNXh9Vg2svBTFXBQ4CpM/EL6Ej8bkvhBKvTfXBheeIak0csinFLzuGG/LAdAGRhGBA82Zr4b6uuGvwSWZ1Hrzo3DZgEGD5S1yOwC7hPSn8PAa38VF1I NNTP-Posting-Date: Sun, 18 Mar 2012 23:24:49 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="JMygcqrYQIbgisnLvkXmZMdWQDNOVF1WHS31s8g6KwqzRDvjhbMDP4SVgiIe5aLn+OVOp8bMP8BQhVs7IXORXWVKXns3uu7g9sIur7hIen1XKSYA2mC8KC7dTODNSJJ5"; mail-complaints-to="abuse@albasani.net" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Cancel-Lock: sha1:TvXvpU2SVb10dOhQm+I5h3lbpjE= sha1:jAY+xYyPGPgNDZomPmlO7lXQgDk= Xref: csiph.com comp.lang.perl.misc:4797 >>>>> "TM" == Tim McDaniel writes: TM> In article <87ty1lu2z7.fsf@stemsystems.com>, TM> Uri Guttman wrote: >>>>>>> "TM" == Tim McDaniel writes: >> TM> In article <87limyk471.fsf@Gmail.com>, XeCycle 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