Scope modifiers: Difference between revisions
Content deleted Content added
Underscore (talk | contribs) →{{header|Perl}}: Reintegrated the discussion of 'state'. |
m →{{header|Perl}}: Changed count of declarations to match the introduction of 'state' |
||
Line 289: | Line 289: | ||
By default, an unqualified name refers to a package variable in the current package. The current package is whatever you set it to with the last <code>package</code> declaration in the current lexical scope, or <code>main</code> by default. But wherever stricture is in effect, using a name that would be resolved this way is a compile-time error. |
By default, an unqualified name refers to a package variable in the current package. The current package is whatever you set it to with the last <code>package</code> declaration in the current lexical scope, or <code>main</code> by default. But wherever stricture is in effect, using a name that would be resolved this way is a compile-time error. |
||
There are |
There are four kinds of declaration that can influence the scoping of a particular variable: <code>our</code>, <code>my</code>, <code>state</code>, and <code>local</code>. <code>our</code> makes a package variable lexically available. Its primary use is to allow easy access to package variables under stricture. |
||
<lang perl>use strict; |
<lang perl>use strict; |