Thread abgedrehtes problem mit switch: oder bin ich blind?
(71 answers)
Opened by deepblack at 2004-06-16 21:56
[quote=Dieter,07.07.2004, 14:55]
- Ein BEGIN Block ist 'immer' die 'erste Tat' des Compilers - Ein BEGIN Block wird compiliert und ausgeführt, noch 'bevor' sich der Compiler um den Rest des Programms kümmert [/quote] perlmod.pod:A "BEGIN" subroutine is executed as soon as possible, that is, the moment it is completely defined, even before the rest of the containing file is parsed. d.h. der teil des programms vor dem BEGIN wird geparsed. somit auch ein my $x; vor dem BEGIN-block. siehe beispiel unten mit strict. Quote doch, der teil vor BEGIN ist bekannt. noch nicht ausgeführt, aber bekannt. dazu gehören deklarationen wie my(), our() etc. Quote ok Quote ja, wobei aber speziell print $x; BEGIN { our $x = 23; } nicht unter strict läuft, weil das print vorher geparsed wird. Quote was soll das heissen? du meinst also etwa BEGIN { $x = 1234; }? in dem fall ist $main::x gemeint, also global, richtig. aber mit einem my $x; vorher ist es nicht mehr $main::x, also nicht global, sondern lexikalisch. hier der beweis: Code: (dl
)
1 tina@tuxedo:~> perl -wle' $y ist package-global, $x nicht. Quote bitte... Code: (dl
)
1 tina@tuxedo:~> perl -Mstrict -wle' Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: ![]() ![]() |