Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Code style advice: where to put "use" statements?

by kyle (Abbot)
on Feb 27, 2008 at 04:44 UTC ( #670481=note: print w/ replies, xml ) Need Help??


in reply to Code style advice: where to put "use" statements?

I've seen that practice also. I think it can make sense if some_function is the only place SomeModule is used. That way if the sub changes so that it doesn't use that module anymore, you can get rid of the use line right there.

That said, I've never done it myself. The top of any module tends to look like this:

package MyApp::Foo; use strict; use warnings; use Core::Module qw( import these ); use CPAN::Module; use MyApp::Module; use MyApp::Other::Module;

I put the pragmas at the very top. Local modules are grouped together, and external modules are grouped together.

I'd rather have everything at the top like that. The practice you show is liable to get cluttered, using the same module in multiple places. That doesn't cost anything in terms of resources, but I think it's a small speedbump to comprehension.


Comment on Re: Code style advice: where to put "use" statements?
Select or Download Code
Re^2: Code style advice: where to put "use" statements?
by emazep (Priest) on Feb 27, 2008 at 23:35 UTC
    This is exactly the same layout that I use (the same module blocks, the same blocks order and even the same newlines between the blocks ;-)

    Ciao,
    Emanuele.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2014-07-24 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (156 votes), past polls