use statements in packages

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
So I was reading up on Dist::Zilla and I see a code snippet like:

    use strict;
    use warnings;
    package Your::Library;


I was always under the impression the "package" statement was the
first thing. Is there some advantage to having the use statements
above the package declaration?


Re: use statements in packages

Quoted text here. Click to load it

No, it make no difference. Pragmas like 'strict' and 'warnings' are
lexically-scoped rather than package-scoped, so any code that follows
them in the file will be affected, regardless of which package it's in
(unless they're overridden with a 'no <foo>', of course).

I wouldn't write them like that, simply because I tend to put modules
like 'Carp' next to strict and warnings, and in that case it *does* make
a difference: if you 'use Carp' in the wrong package, the subs will be
exported to the wrong place.


Site Timeline