%{$var}
和%$var
之間的區別是什麼?我想這個代碼,但有錯誤:
each on reference is experimental at test.pl line 21. Type of argument to each on reference must be unblessed hashref or arrayref at test.pl line 21.
use feature 'say';
%HoH = (
1 => {
husband => "fred",
pal => "barney",
},
2 => {
husband => "george",
wife => "jane",
"his boy" => "elroy",
},
3 => {
husband => "homer",
wife => "marge",
kid => "bart",
},
);
for ($i = 1; $i <= 3; $i++) {
while (($family, $roles) = each %$HoH{$i}) {
say "$family: $roles";
}
}
但這個代碼工作正常:
use feature 'say';
%HoH = (
1 => {
husband => "fred",
pal => "barney",
},
2 => {
husband => "george",
wife => "jane",
"his boy" => "elroy",
},
3 => {
husband => "homer",
wife => "marge",
kid => "bart",
},
);
for ($i = 1; $i <= 3; $i++) {
while (($family, $roles) = each %{$HoH{$i}}) {
say "$family: $roles";
}
}
可能重複[在$ {var},「$ var」和「$ {var}」在Bash shell中有什麼區別?](http://stackoverflow.com/questions/18135451/what- is-the-the-var-var-and-var-in-the-bash-shell) – Emna
@Emna:OP語言是* Perl * ... – MarcoS
在代碼中使用'use strict'。 – eballes