One difference between the three variables defined in Perl

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.