perl - How can I fetch a hash ref from array of hashes by one of its values? -



perl - How can I fetch a hash ref from array of hashes by one of its values? -

i have array of hashes, each hash containing same keys values unique. on basis of particular value, need store hash ref.

see below illustration understand properly:

my @aoaoh = ( { => 1, b => 2 }, { => 3, b => 4 }, { => 101, b => 102 }, { => 103, b => 104 }, );

now check if hash key a contains value 101. if yes need store whole hash ref.

how that?

my $key = "a"; ($ref) = grep { $_->{$key} == 101 } @aoaoh;

or using list::util's first():

use list::util 'first'; $ref = first { $_->{$key} == 101 } @aoaoh;

arrays perl hash reference perl-data-structures

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -