Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: What is the scope of BEGIN? Or... when does it "begin?"

by Ben Win Lue (Friar)
on May 06, 2005 at 08:10 UTC ( #454624=note: print w/ replies, xml ) Need Help??


in reply to What is the scope of BEGIN? Or... when does it "begin?"

I am puzzled, too. So far I did things like:

use strict; BEGIN{unshift (@INC,"\\mylib");} use mylib1;
Which worked perfectly. After reading argvs node, I tested:

use strict; use mylib1; BEGIN{unshift (@INC,"\\mylib");}
Which produced an error. So far I thought BEGIN{} would be executed always before anything else...


Comment on Re: What is the scope of BEGIN? Or... when does it "begin?"
Select or Download Code
Re^2: What is the scope of BEGIN? Or... when does it "begin?"
by Mutant (Priest) on May 06, 2005 at 08:38 UTC
    See tlm's reply above. use is impicitly wrapped in a BEGIN. And since BEGIN's have no precedence over each other, your second example is effectively:
    BEGIN { require mylib1; mylib1->import(); unshift (@INC,"\\mylib"); }
    (I left out 'use strict' for simplicity's sake).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2014-07-26 19:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (178 votes), past polls