Perl Programming/Keywords/state

Previous: stat Keywords Next: study

The state keyword edit

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 edit

  state VARIABLES
  state TYPE VARIABLES
  state VARIABLES : ATTRIBUTES
  state TYPE VARIABLES : ATTRIBUTES

See also edit

Previous: stat Keywords Next: study