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:
Kent Fredric
Date:
January 7, 2014 16:02
Subject:
Re: [perl #120941] The => operator doesn't quote v-strings in "useconstant v1 => 42"
Message ID:
CAATnKFCgf5uyvoPZh5+HB1xKaqquznN6S7vT0WTjmBFua5ygwA@mail.gmail.com
On 7 January 2014 22:04, Johan Vromans <jvromans@squirrel.nl> wrote:

> Yes, but the syntax of 'use' is (perdoc -f):
>
>   use Module VERSION LIST
>
> and not
>
>   use Module VERSION , LIST
>
> (note the comma).
>


Indeed, seems obvious given that criteria that

use Module 1, 2;  # Valid, passes [ 1, 2 ]

and

use Module 1 => 2; # Syntax error

it seems they'd aught to parse the same way. Just they don't.

    use v5.18;
    use warnings;
    use utf8;

    BEGIN {
        package TestClass;

        our $VERSION = 9999;

        use Data::Dump qw(pp);

        sub import {
            my ( $self, @args ) = @_;
            pp \@args;
            1;
        }
        $INC{'TestClass.pm'} = 1;
    }

    my @code = (
        q[use TestClass 1 => 2],
        q[use TestClass v1 => 2],
        q[use TestClass 1 2],
        q[use TestClass v1 2],

        q[use TestClass 1, 2],
        q[use TestClass v1, 2],

        q[use TestClass ( 1 => 2 )],
        q[use TestClass ( v1 => 2 )],

    );

    for my $code ( @code ) {
        say '--';
        say "$code";
        eval $code or say $@;
    }

__[ output ]__

--
use TestClass 1 => 2
syntax error at (eval 1) line 1, near "use TestClass 1 =>"

--
use TestClass v1 => 2
syntax error at (eval 2) line 1, near "use TestClass v1 =>"

--
use TestClass 1 2
[2]

--
use TestClass v1 2
[2]

--
use TestClass 1, 2
[1, 2]

--
use TestClass v1, 2
[v1, 2]

--
use TestClass ( 1 => 2 )
[1, 2]

--
use TestClass ( v1 => 2 )
["v1", 2]


--
Kent
<http://kent-fredric.fox.geek.nz>

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