"Our"," The name is limited to a certain range ", in fact, is to clearly declare a" global variable ", although defined in a module or function, can be accessed outside, if it has already been declared, use "our" again to indicate that the global variable is used, not the private or local variable with the same name. Our $ program_name = "waiter "; { My $ program_name = "something "; Our $ program_name = "server"; # The our here is the same as the outside, which is different from the previous sentence. # The Code called here shows "server" } # The Code executed here still shows "server ". "My"," The name and value are limited to a certain range. "Simply put, this variable can only be seen by the module or function at the current layer, but not by the module or function at the higher or lower layers. Sub greeting1 { My ($ Hello) = "how are you do? "; Greeting2 (); } Sub greeting2 { Print "$ Hello/N "; } $ Hello = "How are you doing? "; Greeting2 (); Greeting1 (); Greeting2 (); Running result: How are you doing? How are you doing? How are you doing? -------------------------- How are you do? No. When you call greeting2 in greeting1, greeting2 cannot see the private $ Hello variable of greeting1. Only the external global variable $ hello can be seen. "Local"," Limiting the value to a certain range ", also known as" dynamic lexical range ", is a bit hard to understand. In my understanding, the functions at the current layer and the lower layer of the current layer can see the variables at the current layer, but the functions at the upper layer cannot. What is the scope depends not only on the functions of the current layer, but also on the program length and depth of the next layer, so it is called "dynamic range ". Sub greeting1 { Local ($ Hello) = "how are you do? "; Greeting2 (); } Sub greeting2 { Print "$ Hello/N "; } $ Hello = "How are you doing? "; Greeting2 (); Greeting1 (); Greeting2 (); Running result: How are you doing? How are you do? How are you doing? ----------------------- Is it different from my? When greeting1 calls greeting2, greeting2 can see the local variable $ Hello of greeting1, and the external global variables are hidden. |