Functions of Perl variables: My, our, local, and global variables

Source: Internet
Author: User

Variables defined in Perl are global by default.
1) My function: limits the name and value of a variable to a certain range. That is to say, the variable can only be a module or function at the current layer.
You can see that this variable is invisible at the upper or lower layers.
2) Our: to limit the variable name to a certain range, it is actually to explicitly declare a "global variable", although it is in
It is defined in the module or function and can be accessed outside the module. If it has been declared, use our again to indicate the our variables used here and previously declared
Is the same.
3) Local: The value is limited to a certain range. What makes the range different from my is that it contains the lower layer of the current layer and the lower layer of the current layer,
However, the upper layer of this layer cannot be accessed.
4) global variables
Use vars QW ($ szversioncode, $ szversionnmae) to define the variables $ szversioncode and $ szversionname
Global variable. Its role is equivalent to that of our. Because it appears after my and our appears before a period of time, you can
We can see that the definition of global variables in some books continues this definition method, but I suggest that you use the our keyword to define global variables.

PS: When Perl does not use strict 'vars', we can use variables without implementation.

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.