develooper Front page | perl.perl5.porters | Postings from June 2022

Re: pre-RFC: template strings

Thread Previous | Thread Next
From:
book
Date:
June 15, 2022 15:22
Subject:
Re: pre-RFC: template strings
Message ID:
Yqn5Jw24g1bXwblR@kapow.home
> This eliminates the need for the `@{[ … ]}` form in qq strings. It
> means you can easily interpolate method calls and simple expressions
> like $a+$b.

Just noting that `${ \… }` exists already, although it's even more
confusing that `@{[ … ]}`:

    $ perl -E 'sub foo { say "wantarray: ", wantarray }  "${\foo}"'
    wantarray: 1

The `\` operator provides a list context to the function being called,
and the scalar dereference grabs the list in scalar context and return
the last element of it:

    $ perl -E 'sub foo { @a = 0..5 } say "${\foo}"'
    5

So, yeah, we probably need something less ugly and less surprising.

-- 
 Philippe Bruhat (BooK)

 Friends are people who are there when you need them. (also applies to dogs)
                                    (Moral from Groo The Wanderer #43 (Epic))

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About