Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

This came up during a code review today. I was reviewing code like this:

sub some_function { use SomeModule; # ... }
Now, I tend to put all use statements at the top of the file. Occasionally, I might put a require statement inside a sub if the module is big and slow to load or unavailable on some platforms, because require is performed at run time. However, given that use statements are performed at compile time, it seems confusing to me to put a use statement inside a sub.

I couldn't find any style advice on this issue in either Perl Best Practices or Perl::Critic. What advice would you give?


In reply to Code style advice: where to put "use" statements? by eyepopslikeamosquito

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [LanX]: hippo you asked about translating Asterix ?
    [Eily]: Maybe the puns in his dialogues were somehow kept through translation, but I can tell he lost his accent
    [LanX]: qui?
    [Eily]: Astérix
    1nickt gives up on finding a Perl YAML parser that supports hash merging. In 2017.
    [LanX]: Oh yes true, he lost his accent! xD
    [Eily]: and since his name is a modified version of astérisque (asterisk), which is a typographical symbol, I think it's even funnier that he would lose a diacritic

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (13)
    As of 2017-05-24 14:56 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?