%{$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";
}
}
[Bashシェルの$ {var}、 "$ var"、 "$ {var}"の違いは何ですか?](http://stackoverflow.com/questions/18135451/what- var-var-and-the-the-bash-shellの違いです) – Emna
@Emna:OP言語は* Perl *です... – MarcoS
あなたのコードで 'use strict'を使用してください。 – eballes