В чем разница между %{$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?] (Http://stackoverflow.com/questions/18135451/what- is-the-difference-between-var-var-and-var-in-the-bash-shell) – Emna
@Emna: язык OP * Perl * ... – MarcoS
Используйте 'use strict' для вашего кода. – eballes