3

これは機能しません:

 my %y = ("lkj",34);
 my %i = ("lkj",66);
 my @e = (\%y, \%i);
 my $u = ${%{$e[0]}}{"lkj"};

しかし、これは:

         my %u = %{$e[0]};
         print $u{"lkj"};

その余分な行を入力したくない場合は、どうすればよいですか。

4

1 に答える 1

8

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 } );
于 2012-05-22T00:28:18.947 に答える