- 論壇徽章:
- 46
|
有點想不明白是怎么回事,為什么hash不能自動將那個value 1變?yōu)橐粋hash的ref?
把 1 自動變 hashref 是怎么個邏輯,腦袋秀逗了?
autovivification 特性是有嚴格要求的,只對不存在的或值為undef 的項自動生hashref 或 arrayref。
你這里 1 明顯不是 undef 是個有意義的值,按你想的那類型系統(tǒng)也太隨意了,怎么能悄無聲息的擦除我有用的值,我只是拼寫錯誤怎么辦?當然如果你不開 use strict; 那代碼會成功執(zhí)行的,只是變成符號引用多了個 %1 全局變量。。∵@是個錯誤示范,永遠用 use strict;
autovivification
A Graeco-Roman word meaning “to bring oneself to life”. In Perl, storage locations (lvalues) spontaneously generate themselves as needed, including the creation of any hard reference values to point to the next level of storage. The assignment $a[5][5][5][5][5] = "quintet" potentially creates five scalar storage locations, plus four references (in the first four scalar locations) pointing to four new anonymous arrays (to hold the last four scalar locations). But the point of autovivification is that you don’t have to worry about it.
AV
二樓人很熱心,不過這里吐槽偏太遠了 和 -> 沒有關系,兩級索引之間的 -> 可以省略,因為只要是兩級索必定要解引用 |
|