< Perl Programming < Keywords
The
The state
keyword
state
declares a lexically scoped variable like my
, but variables declared with state
will never be reinitialized
If the variable list VARIABLES
of state
has more than one element, the list has to be placed in brackets. In such a list, undef
can be used as a placeholder.
If more than one state
with the same name are declared within the same lexical scope, Perl issues a warning, as it is the case with multiple declarations, but they are seen as redundant.
state
variables can only be used with the use feature "state"
pragma, unless it is written fully as CORE::state
.
Syntax
state VARIABLES
state TYPE VARIABLES
state VARIABLES : ATTRIBUTES
state TYPE VARIABLES : ATTRIBUTES
See also
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.