Re: Lifetime of my variables?



Shmuel (Seymour J.) Metz <spamtrap@xxxxxxxxxxxxxxxxxxxxxxxxxx> writes:

I could find nothing in the Perl documentation on the lifetime of my
variables. The scope of the name is lexical, but what about the value?
Specifically, if a my variable is declared in a block, does it retain
its value from the previous time you entered the block?

Basically you get a new variable each time you reach the my statement.

If you want to have a variable that keeps the vallue between each time
you enter the block, you should look at state variables. See the perlsub
manual page, the section titled "Persistent Private Variables".

//Makholm
.



Relevant Pages