Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2005
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow Array of Hashes, assign value to hash1 using key ref

    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?

  • #2
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    maybe your code does not work because you have:

    $hostgroup_ref->{'membesr'}

    instead of:

    $hostgroup_ref->{'members'}

    use "strict" and "warnings" in the future


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •