...

View Full Version : Array of Hashes, assign value to hash1 using key ref



ganesh_mak
09-18-2009, 05:13 PM
I have an array of hashes

#! /usr/bin/perl

my $host_ref;
my @aoh = (
{group_name => 'linux', group_alias => 'LINUX', members => '10'},
{group_name => 'Net', group_alias => 'Net-LINUX', members => '20'},
{group_name => 'SIP', group_alias => 'SIP-LINUX', members => '30'},
{group_name => 'Admin', group_alias => 'Admin-LINUX', members => '10'}
);

foreach my $hostgroup_ref(@aoh){
if($hostgroup_ref->{'membesr'} == 10) {
$hostgroup_ref->{'group_name'} = "MYLINUX"; # does it retain the value #after the loop
}
$host_ref->{'hostgroup'} = $hostgroup_ref;
$hostgroup_ref->{'host'}->{$host_ref->{'host_name'}} = $host_ref;
}


# here if i retreive the value of @aoh
# does it replace the $hostgroup_ref->{'group_name'}=> 'linux' with $hostgroup_ref->{'group_name'} = "MYLINUX";

To replace the value with new one what i have to do there while assiging?

KevinADC
09-18-2009, 05:53 PM
maybe your code does not work because you have:

$hostgroup_ref->{'membesr'}

instead of:

$hostgroup_ref->{'members'}

use "strict" and "warnings" in the future



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum