Home >> perlsubroutines >>
When to use my local?
Variables declared with the my() construct are considered to be lexical local variables. These variables are not entered in the symbol table for the current package; therefore, they are totally hidden from all contexts other than the local block within which they are declared. Even subroutines called from the current block cannot access lexical local variables in that block.Lexical local variables must begin with an alphanumeric character (or an underscore).
Variables declared by means of the local() construct are considered to be dynamic local variables. The value is local to the current block and any calls from that block. You can localize special variables as dynamic local variables, but you cannot make them into lexical local variables. These two differences from lexical local variables show the two cases in Perl 5.0 in which it is still advisable to use local() rather than my():
Use local() if you want the value of the local variables to be visible to subroutines.
Use local() if you are localizing special variables.
Perl functions
|
Perl Subroutines
Download perl
download stable version of perl
Perl 5.10.1
|
|