develooper Front page | perl.perl5.porters | Postings from January 2014

Re: [perl #120941] The => operator doesn't quote v-strings in "useconstant v1 => 42"

Thread Previous | Thread Next
From:
Brad Gilbert
Date:
January 7, 2014 08:30
Subject:
Re: [perl #120941] The => operator doesn't quote v-strings in "useconstant v1 => 42"
Message ID:
CAD2L-T2d_rK-s-6tW1FrTsOEyX+EG7fpqyo=51coA-0gNP20gw@mail.gmail.com
On Tue, Jan 7, 2014 at 1:21 AM, Johan Vromans <jvromans@squirrel.nl> wrote:
> Leon Timmermans <fawaka@gmail.com> writes:
>
>> use optionally takes a version, so that is parsed as «use <module>
>> <version> <expression>», and => is not a valid start of an expression.
>
> The question is: is this desired (a.o.t. actual) behaviour, or should
>
>   use constant v1 => 1;
>
> DWIM?
>

I would expect that to be the equivalent to `use constant ('v1',1)`
It is definitely being parsed as the version part of the `use`
statement because it works
if you place it in parens `use constant (v1 => 1)`

Although it makes it more difficult to create a v-string with a single
element of ordinal 1.

    perl -MDevel::Peek -E'use constant "v1" => 2;$v= v1;say Dump $v'

    perl -MDevel::Peek -E'use constant "v1" => 2;$v= v01;say Dump $v'
    perl -MDevel::Peek -E'use constant "v1" => 2;$v= do{package
clean;v1};say Dump $v'

So creating a subroutine matching `/\Av[0-9]+\z/` should probably be
discouraged.
Maybe even going so far as having `constant` warn if you ask it to
create a constant with a matching name.

( Further discussion of having constant warn, or adding a discouragement
to the docs should be brought up in a new thread )

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