Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

A Matter of Style

by Anonymous Monk
on Oct 22, 2012 at 18:57 UTC ( #1000402=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Greeting, fellow monks, I happen to start my modules like this:
use 5.010; use strict; use warnings; package Foo::Bar; use Data::Dumper; use IO::Handle; ...
since AFAIK, pragmas extend to the end of the file, while a file may contain multiple packages (which mine do, sometimes). So, most modules in the standard Perl distribution put the "package" on top. I know this is not a big issue, both syntactically and semantically, but still I would like to know your opionion about the "right" style to start a Perl package...

Comment on A Matter of Style
Download Code
Re: A Matter of Style
by choroba (Abbot) on Oct 22, 2012 at 19:20 UTC
      Thank you very much, I guess I should have done my homework.
Re: A Matter of Style
by tobyink (Abbot) on Oct 22, 2012 at 20:27 UTC

    If you brace your packages, a la:

    { package Foo::Bar; use strict; ...; } package Foo::Bar; { use strict; ...; } # Perl 5.14+ package Foo::Bar { use strict; ...; }

    ... then it makes a difference, because lexically scoped pragma such as strict will end with the closing brace.

    If you put multiple packages in the same file, then there are good arguments in favour of bracing each package - to prevent, e.g. leakage of our variables.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: A Matter of Style
by Anonymous Monk on Oct 22, 2012 at 20:40 UTC
    The number-one rule of Good Style is: consistency. Pick a way of saying it, make sure that it says what you think it does, and do it exactly the same way every time within a project.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1000402]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2014-08-29 22:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (289 votes), past polls