develooper Front page | perl.perl6.users | Postings from October 2020

Re: Brace interpolation in strings creates a new scope?

Thread Previous | Thread Next
Elizabeth Mattijsen
October 26, 2020 19:04
Re: Brace interpolation in strings creates a new scope?
Message ID:
> On 26 Oct 2020, at 18:40, Sean McAfee <> wrote:
> Is this the intended behavior?  The doc page on quoting constructs just says that values can be interpolated with braces, but (at least to my eyes) doesn't suggest that this involves creating a new scope, or a new function, or however it is that this happens.

I guess we need to update the documentation.  But the braces inside a double quoted string *do* create a new scope, causing the behaviour of ++$ that you have seen.

> For my presentation I can just alter some lines to:
>     say "You called me ", ++$times, " times";
> and
>     say "You called me ", ++$, " times";
> ...but that seems a bit less elegant than what I had originally.

Alternately you could do:

   say "You called me " ~ ++$ ~ " times";

Personally, I would avoid the use of the anonymous state variable.  I think it is an example where Larry would nowadays apply rule #2.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About