跳轉到內容

Perl 程式設計/關鍵字/state

來自華夏公益教科書,開放的書籍,開放的世界
前一個:stat 關鍵字 下一個:study

state 關鍵字

[編輯 | 編輯原始碼]

state 宣告一個詞法作用域變數,類似於 my,但使用 state 宣告的變數永遠不會被重新初始化。

如果 state 的變數列表 VARIABLES 包含多個元素,則該列表必須放在括號中。在這樣的列表中,undef 可以用作佔位符。

如果在同一個詞法作用域內聲明瞭多個具有相同名稱的 state,Perl 會發出警告,就像多個 宣告一樣,但它們被視為冗餘的。

state 變數只能與 use feature "state" 準則一起使用,除非它被完全寫成 CORE::state

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

另請參閱

[編輯 | 編輯原始碼]
前一個:stat 關鍵字 下一個:study
華夏公益教科書