[Israel.pm] (no subject)
Gaal Yahas
gaal at forum2.org
Fri Mar 17 03:21:20 PST 2006
[Replying to Shlomi's post although probably he knows this already.]
On Fri, Mar 17, 2006 at 01:01:45PM +0200, Shlomi Fish wrote:
> On Thursday 16 March 2006 23:10, Sagiv Barhoom wrote:
> > Gabor, could you please explain why ${10} is better then $10?
>
> Well, generally, in Perl one can use the ${ ... } notation to signify when the
> name of the variable inside the interpolation ends. So if for example I want
> to have something like :
>
> $myvar . "hello" . $q . "Sagiv"
>
> I can write it as:
>
> "${myvar}hello${q}Sagiv"
>
> Whereas:
>
> "$myvarhello$qSagiv"
>
> Will be interpreted as the variable $myvarhello followed by $qSagiv.
Perl 6 has {} as a general introducer of closure interpolation, so this is
even clearer there:
"{ $myvar }hello{ $q }Sagiv"
The spaces are optional, and the nice thing is that you can put any
expression there. So this works too:
"I think I need { what_I_need($now) + $spare } of them."
In Perl 5 there's the @{[]} syntax to do something similar but that is
significantly more ugly, and has subtle context issues, too.
--
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/
More information about the Perl
mailing list