Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: Strict and warnings: which comes first?

by jcb (Parson)
on Nov 09, 2019 at 00:25 UTC ( [id://11108499]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Strict and warnings: which comes first?
in thread Strict and warnings: which comes first?

You are right: I think of package as part of the file header, so it goes in the very first line in a module, like the #! line in a script. I think that most of my code would probably run under 5.6, so my scripts generally lack use VERSION. I may need to see about changing that. :-)

Replies are listed 'Best First'.
Re^4: Strict and warnings: which comes first?
by tobyink (Canon) on Nov 09, 2019 at 14:54 UTC

    Since Perl 5.12, package has started to become more interesting. You can do stuffs like:

    use v5.16; use strict; use warnings; package Foo::Bar 1.2 { ...; }

    Although the extended syntax for package doesn't need feature or a use VERSION line to enable it, it seems like a good idea to put the use VERSION before it rather than after, so people with older Perls get an error message about their Perl being too old, instead of an error message about being unable to parse the package statement.

    And even in cases where I'm supporting older Perls, I keep all that stuff before package.

    Sometimes I'll also use modules before package if I know I'm not importing anything into my namespace from them, like:

    use v5.16; use strict; use warnings; use Scalar::Util (); package Foo::Bar 1.2 { ...; my $addr = Scalar::Util::refaddr($ref); # use fully-qualified nam +e because not imported }

      That is nice syntactic sugar if you want multiple versioned packages in the same file, but I usually keep to "one package per module file" and keeping package on the first line is helpful with other tools; this is similar to the insistence in the GNU Coding Standards that function names begin in the leftmost column. It is a convention that makes files easier for me to process with other (written on the spot one-shot) tools.

      And even in cases where I'm supporting older Perls, I keep all that stuff before package.
      I like that! I just adapted my package template to do the same. I'll not use strict; in versions newer than 5.12 though, because it is already included, and I'll stick to package Foo::Bar 1.2; if I have only one namespace in one file (which is the overwhelming majority).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11108499]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-03-29 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found