Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Why perl with strict allows to use -bareword?

by hurricup (Pilgrim)
on Jun 27, 2017 at 20:04 UTC ( [id://1193722]=perlquestion: print w/replies, xml ) Need Help??

hurricup has asked for the wisdom of the Perl Monks concerning the following question:

According to docs for strict subs:

This disables the poetry optimization, generating a compile-time error if you try to use a bareword identifier that's not a subroutine, unless it is a simple identifier (no colons) and that it appears in curly braces or on the left hand side of the => symbol.

But use Some::Thing -base;, for example, works and not looks like example in docs. Also, it may cause a surprise, when sub with name 'base' been defined before this use.

Replies are listed 'Best First'.
Re: Why perl with strict allows to use -bareword?
by Anonymous Monk on Jun 27, 2017 at 20:14 UTC
      Thank you. Guess this should be mentioned in stricts
Re: Why perl with strict allows to use -bareword?
by Anonymous Monk on Jun 27, 2017 at 20:26 UTC
    it may cause a surprise, when sub with name 'base' been defined before this use

    That doesn't make sense: if sub blah has been defined then blah and -blah are not barewords, they are function calls

    use warnings; use strict; BEGIN { $INC{'Blah.pm'}=1 } sub Blah::import { print "@_\n" } sub abc { 42 } use Blah -abc; # "Blah -42" use Blah -def; # "Blah -def"
      What the parser considers a bareword does depend on what it's seen tho.
      use warnings; use strict; BEGIN { $INC{'Blah.pm'}=1 } sub Blah::import { print "@_\n" } sub abc { 42 } use Blah -abc; # "Blah -42" use Blah -def; # *still* "Blah -def" sub def { 999 }
      Barewords: "A word that has no other interpretation in the grammar will be treated as if it were a quoted string. ... use strict 'subs'; then any bareword that would NOT be interpreted as a subroutine call produces a compile-time error instead."
      Yes, and I expected compilation failure if sub with such name was not defined. According to docs.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1193722]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found