Perl generally has three methods to define a variable: 1. $ Var = "XXX" 2. local ($ var) = "XXX" 3. my ($ var) = "XXX" the first method is to define a global variable, the second method is to define a local variable, and the third method is to define a variable of the my type. Currently, I know that the three variables have different definitions in terms of scope. The following example illustrates this. Variable $ Var = "Global"; # Life global variable $ VaR
& Print_var (); # The output result is global.
& Print_local (); # The output result is: Local
# The act of the variables declared in print_local continues to the child routine called by print_local.
& Print_my (); # The output result is global.
# VARIABLES declared in print_my are valid only in print_my.
Sub print_var {print "$ Office/N";} sub print_local {local ($ var) = "local"; & print_var ();}
Sub print_my {My ($ var) = "my"; & print_var ();}
Bytes -----------------------------------------------------------------------------------------------------------
2007/11/21