{ a => 'b' }->{$k};
####
my $hash_ref = { a => 'b' };
# and then
$hash_ref->{$k}
####
use strict;
use warnings;
use Benchmark qw(cmpthese);
our $global_hash = { 'a' => 'A', 'b' => 'B'};
my $lexical_hash = { 'a' => 'A', 'b' => 'B'};
use constant CONST_HASH => { 'a' => 'A', 'b' => 'B'};
cmpthese(-2, {
'hash' => sub { for my $x (qw(a b a b a b)) { my $y = { 'a' => 'A', 'b' => 'B'}->{$x}; }},
'global_ref' => sub { for my $x (qw(a b a b a b)) { my $y = $global_hash->{$x}; }},
'lexical_ref' => sub { for my $x (qw(a b a b a b)) { my $y = $lexical_hash->{$x}; }},
'const' => sub { for my $x (qw(a b a b a b)) { my $y = CONST_HASH()->{$x}; }},
});
####
Rate hash global_ref lexical_ref const
hash 27571/s -- -73% -74% -76%
global_ref 102819/s 273% -- -3% -10%
lexical_ref 105720/s 283% 3% -- -8%
const 114361/s 315% 11% 8% --