in reply to Re^3: Hacking Perl Code
in thread Hacking Perl Code
You can now compare the two solutions: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)};
while with my script you'll see: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
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 6-end
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 2-unitcheck strict 1.04 warnings 1.12
Thanks for the opportunity to learn something more.some_win>perl used_modules.pl test_of_executed_code.pl 1-begin strict 1.04 warnings 1.12
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Hacking Perl Code
by LanX (Saint) on Apr 09, 2014 at 17:06 UTC | |
by Discipulus (Canon) on Apr 09, 2014 at 19:39 UTC |