CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [nramya82] Very urgent Complicated datastructre and after merging just giving numeric value : Edit Log



Zhris
Enthusiast

Oct 24, 2013, 6:19 AM


Views: 8111
Re: [nramya82] Very urgent Complicated datastructre and after merging just giving numeric value

Hi,

There is a lot wrong with your code, I don't understand how you managed to compile it. Based on what you have provided, here is my re-write, which I cannot properly test:


Code
sub locallb_get_member_v2  
{
my $ENABLED_STATUS_MAP =
{
ENABLED_STATUS_NONE => 'NONE',
ENABLED_STATUS_ENABLED => 'ENABLED',
ENABLED_STATUS_DISABLED => 'DISABLED',
ENABLED_STATUS_DISABLED_BY_PARENT => 'DISABLED_BY_PARENT'
};

my $AVAILABILITY_STATUS_MAP =
{
AVAILABILITY_STATUS_NONE => 'Error scenario',
AVAILABILITY_STATUS_GREEN => 'GREEN',
AVAILABILITY_STATUS_YELLOW => 'YELLOW',
AVAILABILITY_STATUS_RED => 'RED',
AVAILABILITY_STATUS_BLUE => 'BLUE',
AVAILABILITY_STATUS_GRAY => 'GRAY'
};

my $member_lists = $soapResponse->result;
my $memberobjectstatus = $soapResponse->result;

my $members = { };

for (0 .. $#{$member_lists})
{
my $address = $member_lists->[$_]->{address};
my ($ip) = $address =~ /\/([^\/]+)$/;
my $port = $member_lists->[$_]->{port};
my $enabled = $ENABLED_STATUS_MAP->{$memberobjectstatus->[$_]->{enabled_status}};
my $availability = $AVAILABILITY_STATUS_MAP->{$memberobjectstatus->[$_]->{availability_status}};

$members->{$address} =
{
ip => $ip,
port => $port,
enabled => $enabled,
availability => $availability
};
}

return $members;
}



Code
my $membershref = $bigip->locallb_get_member_v2( $bigip_host, $pool );  
printError("Failed to find members for $pool") unless (keys %$membershref);

print "<ul>\n";
for my $address ( sort keys %$membershref )
{
my $ip = $membershref->{$address}->{ip};
my $port = $membershref->{$address}->{port};
my $enabled = $membershref->{$address}->{enabled};
my $availability = $membershref->{$address}->{availability};

printf "\t<li>'%s', %s:%s, enabled:%s, availability:%s</li>\n", $address, $ip, $port, $enabled, $availability;
}
print "</ul>\n";


Note, your two calls of $soapResponse->result return blessed lists of blessed hashes, which you probably shouldn't be accessing directly, but I don't know which module you are using to provide a more appropriate suggestion.

Hope this is useful to you.

Chris


(This post was edited by Zhris on Oct 24, 2013, 2:29 PM)


Edit Log:
Post edited by Zhris (Enthusiast) on Oct 24, 2013, 6:23 AM
Post edited by Zhris (Enthusiast) on Oct 24, 2013, 6:24 AM
Post edited by Zhris (Enthusiast) on Oct 24, 2013, 6:33 AM
Post edited by Zhris (Enthusiast) on Oct 24, 2013, 2:10 PM
Post edited by Zhris (Enthusiast) on Oct 24, 2013, 2:29 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives