Hash value highlighting

This does not work:

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

but it does:

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

If I don't like typing this extra line, what should I do.

+3
source share
1 answer

You are using the operator ->:

$e[0]->{"lkj"}

You can do something similar for arrayrefs, and this is even a chain:

my $eref = \@e;
print $eref->[0]->{"lkj"}

As a bonus, you can complete the entire setup on a single line using shorthand {}for arrayrefs:

my @e = ( { lkj => 34 }, { lkj => 66 } );
+8
source

All Articles