Dear
LanX,
i only meant, as explained in the update of
the original post that my solution only executes any
BEGIN block and no more, while with
perl -c -d:TraceUse script.pl all the
BEGIN UNITCHECK CHECK blocks are executed.
I was wrong (so thanks for your question), because my code also executes any
END blocks and even other
UNITCHECK already present, because those blocks run LIFO.
Here some code to demonstrate the concept. With a script called
test_of_executed_code.pl as follow:
BEGIN{print qq(1-begin\n)};
UNITCHECK {print qq(2-unitcheck\n)};
CHECK {print qq(3-check\n)};
INIT {print qq(4-init\n)};
print qq(5-main\n);
END{print qq(6-end\n)};
You can now compare the two solutions:
some_win>perl -c -d:TraceUse test_of_executed_code.pl
1-begin
2-unitcheck
3-check
Modules used from test_of_executed_code.pl:
test_of_executed_code.pl syntax OK
while with my script you'll see:
some_win>perl used_modules.pl test_of_executed_code.pl
1-begin
2-unitcheck
strict 1.04
warnings 1.12
6-end
The only way i found to prevent the
END blocks to be executed is to change, in the
UNITCHECK part of the original script,
exit; with an ugly
exec qq(perl -e "exit"); that produces:
some_win>perl used_modules.pl test_of_executed_code.pl
1-begin
2-unitcheck
strict 1.04
warnings 1.12
But, considering the LIFO aptitude of the
UNITCHECK blocks, i can do it better and change
eval $begin.$content; with
eval $content.$begin; producing:
some_win>perl used_modules.pl test_of_executed_code.pl
1-begin
strict 1.04
warnings 1.12
Thanks for the opportunity to learn something more.
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.