Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: when is a perl module executed?

by ketaki (Acolyte)
on Jul 17, 2008 at 05:45 UTC ( [id://698245]=note: print w/replies, xml ) Need Help??


in reply to Re^2: when is a perl module executed?
in thread when is a perl module executed?

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^4: when is a perl module executed?
by cdarke (Prior) on Jul 17, 2008 at 08:06 UTC
    You asked if placing code in a package outside subroutines is "right".

    I'm afraid that what is "right" is not that clear cut, it is often a matter of opinion. If you get the result you need then there is a case for saying it is "right". Whether the code is clear, easy to maintain, and efficient is another matter, and often not easy to quantify.

    A BEGIN block is specifically provided for code to be executed once at compile time. Usually this is the best place to put it since it is easy to find. There are some cases where you do need code outside the BEGIN block, but not many. The bulk of a package is "usually" invoked at runtime using subroutines, not "always".
Re^4: when is a perl module executed?
by blazar (Canon) on Jul 18, 2008 at 22:40 UTC

    I personally believe that you're confused (and incidentally the way you like to write tends to confirm that you are:) people clearly told you that you can have code out of subs in modules. That is, it's valid Perl. People generally use modules as collections of reusable code: subs to be imported as additions to the builtins or methods of some class. There's no reason they shouldn't also do things. Indeed, they often have to, to "initialize" in some way or another those collections of code. For example, think of a module which will connect to some site to retrieve some info and build suitable "constants" - it's not that strange...

    --
    If you can't understand the incipit, then please check the IPB Campaign.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-19 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found