Troy May wrote:
>
> Hello,
Hello,
> I just read this in a forum and I have never heard of this before. He was
> having problems with a variable not holding it's value when calling it from
> a sub. He wrote back and said that this is what fixed it. Can anybody
> explain this to me? Here's part of his post:
>
> -------------
> What I've found is that in order to initialise my static variable I need to
> have a BEGIN statement around it:
>
> BEGIN {
>
> my $static = "abc";
>
> sub doit() {
> $static = $static x 2;
> print( "$static \n" );
> }
>
> } # end of BEGIN statement
>
> I hadn't realised that the BEGIN was required and while testing this found
> that $static was not being explicitly initalised prior to its first use.
You don't need a BEGIN block, a plain block will do.
{
my $static = 'abc';
sub doit () {
$static = $static x 2;
print( "$static \n" );
}
}
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]