これは機能しません:
my %y = ("lkj",34);
my %i = ("lkj",66);
my @e = (\%y, \%i);
my $u = ${%{$e[0]}}{"lkj"};
しかし、これは:
my %u = %{$e[0]};
print $u{"lkj"};
その余分な行を入力したくない場合は、どうすればよいですか。
You use the ->
operator:
$e[0]->{"lkj"}
You can do something similar for arrayrefs, and it's even chainable:
my $eref = \@e;
print $eref->[0]->{"lkj"}
As a bonus, you can do all the setup in a single line too by using the {}
shorthand for arrayrefs:
my @e = ( { lkj => 34 }, { lkj => 66 } );