BEGIN <> BEGIN

BEGIN <> BEGIN

Post by Ferry Bolh » Thu, 01 Jun 2006 18:32:02


Hi,

I understand that a "use <module> <vars>;" is similar to

BEGIN {
require <module>;
<module>->import(<args>);
}

When writing BEGIN blocks myself and looking at the
compiled script with B::Deparse, I can see my BEGIN
blocks, but not the BEGIN blocks created by "use".

Are these BEGIN blocks special in some way? Are
these actually BEGIN blocks or just blocks behaving
_similar_ to BEGIN blocks?

Until now, I thought the binary code trees of BEGIN blocks
(and later of CHECK blocks as well) are removed after
they have executed. Is this true? In other words: does a
B::Bytecode-d script still contain BEGIN and CHECK
blocks and are these executed whenever the script starts?
If not, where can I place code I want to be executed
_before_ the main scripts code gets executed? Is it this
what INIT blocks were made for?

MTAI for your answers, and kind greetings from Vienna

Ferry

--
Ing. Ferry Bolhar
Municipality of Vienna, Department 14
A-1010 Vienna / AUSTRIA
E-mail: XXXX@XXXXX.COM
 
 
 

BEGIN <> BEGIN

Post by Bob Anasta » Thu, 01 Jun 2006 21:41:22


hrmm......

this doesnt look like perl to me, is this a mod or style i am not
familiar with? this looks more like C or C++

 
 
 

BEGIN <> BEGIN

Post by xhoste » Fri, 02 Jun 2006 00:22:23


B::Deparse takes many options, you need to play with them.

$ perl -MO=Deparse,-x5 -e 'use CGI;'
sub BEGIN {
require CGI;
do {
'CGI'->import
};
}
-e syntax OK


I'm not sure. B::Deparse does say that:

Note that in a few cases this translation can't be
perfectly carried back into the source code -- if the
loop's initializer declares a my variable, for
instance, it won't have the correct scope outside of
the loop.

I don't know if BEGIN blocks are another of those few cases or not.

Xho

--
-------------------- http://www.yqcomputer.com/
Usenet Newsgroup Service $9.95/Month 30GB
 
 
 

BEGIN <> BEGIN

Post by Paul Lall » Fri, 02 Jun 2006 00:37:44


You need to read
perldoc perlmod
if you don't recognize BEGIN{} blocks.

Paul Lalli
 
 
 

BEGIN <> BEGIN

Post by Ferry Bolh » Fri, 02 Jun 2006 01:04:41

Bob Anastasia:


I've never heard somewhat about BEGIN blocks in C (don't know
C++) - anyway, it's Perl. What are you unfamiliar with?

Greetings, Ferry

--
Ing. Ferry Bolhar
Municipality of Vienna, Department 14
A-1010 Vienna / AUSTRIA
E-mail: XXXX@XXXXX.COM
 
 
 

BEGIN <> BEGIN

Post by Bob Anasta » Fri, 02 Jun 2006 01:43:59


i am just not familiar with the BEGIN block statement, i am in no way
an expert, i have always just called a sub routine to initilize my
program. i guess you learn something new every day, i will definitly
look up perlmod and learn more, thank you.

ps: i wasnt refering it to C or C++, just implying that it looked
foreign to me and that it could be a different language, using C and
C++ as possible options. obviously i was wrong.

sorry