anirudh.agarwal has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, I would like to convert a array of hash ref to hash and check a value in it. This is how it goes. The following code gets the array reference in $ams_hosts
The following codemy $ams_hosts = $request->get_config()->get_ams_hosts($domain);
prints thisprint STDERR Dumper @{$ams_hosts};
Now i would like to check if a scalar variable, say $ams_ip=172.16.133.52, does not exist in the above hash assign undef to $ams_ip. I thought of assigning the array to hash with (key,value) as (deviceIp,<its correspponding ip address like 172.16.133.56> ) I tried the following snippet$VAR1 = { 'domainId' => '1', 'deviceIp' => '172.16.133.56', 'deviceType' => 3, 'deviceName' => 'AMS' }; $VAR2 = { 'domainId' => '1', 'deviceIp' => '172.16.133.57', 'deviceType' => 3, 'deviceName' => 'ams_57' };
but it doesnt work. Please let me know what I am doing wrong and what would make it right. As I am new to perl, I would be obliged to learn from perl monks like you. Your help is highly appreciated. Thanks in advance :) .my %ams_ips_hash = map {$_->{'deviceIp'}++} @{$ams_hosts}; $ams_ip = "" if !exists $ams_ips_hash{ $ams_ip};
|
---|
Back to
Seekers of Perl Wisdom