- 论坛徽章:
- 46
|
有点想不明白是怎么回事,为什么hash不能自动将那个value 1变为一个hash的ref?
把 1 自动变 hashref 是怎么个逻辑,脑袋秀逗了?
autovivification 特性是有严格要求的,只对不存在的或值为undef 的项自动生hashref 或 arrayref。
你这里 1 明显不是 undef 是个有意义的值,按你想的那类型系统也太随意了,怎么能悄无声息的擦除我有用的值,我只是拼写错误怎么办?当然如果你不开 use strict; 那代码会成功执行的,只是变成符号引用多了个 %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
二楼人很热心,不过这里吐槽偏太远了 和 -> 没有关系,两级索引之间的 -> 可以省略,因为只要是两级索必定要解引用 |
|