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
Brad Gilbert
January 7, 2014 08:30
Re: [perl #120941] The => operator doesn't quote v-strings in "useconstant v1 => 42"
Message ID:
On Tue, Jan 7, 2014 at 1:21 AM, Johan Vromans <> wrote:
> Leon Timmermans <> 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;

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
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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About