Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
My subs are always at the top. In my opinion, a sub should be in the file before the point where it's first used. If that isn't possible, for example when two subs call eachother, I put empty declarations above them. If you have subs before everything else, you don't have to wrap it in a BEGIN block if you need simple closures.

My sripts look like this:
#!/usr/bin/perl -w use Module::Foo; use Module::Bar; use Module::Baz qw(foo bar); use strict; sub first { # ... } sub second { # ... } # main code, if applicable


My modules look like:
package Module::Xyzzy use Module::Foo; use Module::Bar; use Module::Baz qw(foo bar); use base 'Exporter'; use Carp use strict; our @EXPORT_OK = qw(...); sub CONSTANT () { 1 } sub new { # I try to always put new before other methods } sub first { # ... } sub second { # ... } sub DESTROY { # If there's a DESTROY method, I put it at the end } # main code - that is: "1;" :) __END__ =pod That's right, I use __END__ and =cut, just to be sure. My documentatio +n is NOT mixed with the code. Whenever code is unclear, I comment it, but I dislike, +no I hate pod and code mixed. =cut


It's just a matter of taste

++ vs lbh qrpbqrq guvf hfvat n ge va Crey :)
Nabgure bar vs lbh qvq fb jvgubhg ernqvat n znahny svefg.
-- vs lbh hfrq OFQ pnrfne ;)
    - Whreq


In reply to Re: where do you put your subs by Juerd
in thread where do you put your subs by greenFox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found