...each line is interpreted and executed before proceeding to the next line.
Test your intuition:
while( <DATA> ) { chomp; if( is_empty($_) ) { print "$.: ---\n" if is_empty($_); } else { print "$.: $_\n"; } goto JUMP if $. == 4; } sub is_empty { return ! length $_[0]; } BEGIN { print "Beginning execution.\n" } JUMP: { print "Look, found the JUMP block.\n"; } __DATA__ First line Third line Fourth line Fifth line
So... the BEGIN{} block executes before everything else. So Perl must have known about it even though it appears physically lower in the file. The is_empty function is declared and defined after it is called, so Perl must have known about it when it executed the line "if( is_empty(...". And the <DATA> filehandle is being read even though its contents appear at the end of the file. And last but not least, goto found JUMP.
Dave
In reply to Re: Perl execution
by davido
in thread Perl execution
by rbala
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |