merlyn,
You are of course correct. It is better to be safe then sorry. Unfortunately, I am a bit confused as to the behavior of the following:
#!/usr/bin/perl
use strict;
use warnings;
INITIALIZE:
{
my $cnt = 1;
sub get_count {
return $cnt++;
}
}
print get_count(), "\n" for 1..10;
goto INITIALIZE if get_count() < 15;
__END__
1..10, 12..21
Care to elaborate?
Update: Explanation from tye in the CB
The re-initialization of $cnt doesn't impact the get_count() sub because it is only defined once at compile time. It however does get re-initialized which may impact other things within the same scope but not in the sub itself. To avoid wasting resources and make the intent clear, using the BEGIN block is a good idea (which I never doubted in the first place).
|