Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Complicated datastructre and after merging giving numeric value need help!!

by nramya82 (Initiate)
on Oct 23, 2013 at 22:16 UTC ( [id://1059360]=note: print w/replies, xml ) Need Help??


in reply to Re: Complicated datastructre and after merging giving numeric value need help!!
in thread Complicated datastructre and after merging giving numeric value need help!!

Thank you for your response. Yes it worked but when I tried to print each value I am just getting hash reference and not the value.

Below is my code in .pm file I need to produce output like this
'/Common/10.116.38.51', 10.116.38.51:1935, enabled:ENABLED, avail +ability:GREEN '/Common/10.116.38.52', 10.116.38.52:1935, enabled:ENABLED, availa +bility:GREEN
from the this
print Dumper(@status); $VAR1 = bless( [ bless( { 'address' => '/Common/10.116.38.51', 'port' +=> '80' }, 'Common::AddressPort' ), bless( { 'address' => '/Common/10 +.116.38.52', 'port' => '80' }, 'Common::AddressPort' ) ], 'Common::Ad +dressPort[]' ); $VAR2 = bless( [ bless( { 'availability_status' => 'A +VAILABILITY_STATUS_GREEN', 'status_description' => 'Pool member is av +ailable', 'enabled_status' => 'ENABLED_STATUS_ENABLED' }, 'LocalLB::O +bjectStatus' ), bless( { 'availability_status' => 'AVAILABILITY_STATU +S_GREEN', 'status_description' => 'Pool member is available', 'enable +d_status' => 'ENABLED_STATUS_ENABLED' }, 'LocalLB::ObjectStatus' ) ], + 'LocalLB::ObjectStatus[]' );

My mail .pm files with has the below code

</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', };
push (@status,@memberobjectstatus); my %members;
foreach my $member (@status){ $members{ $status->{'address'} = $member->{'port'}}; $members{ $status}->{'enabled'} = $ENABLED_STATUS_MAP->{ $status->{'enabled_status'} } ; $members{ $status}->{'availability'} = $AVAILABILITY_STATUS_MAP->{ $status->{'availability_status'} } ;
return \%members; }
</code>

In main cgi i have the below code

my $membershref = $bigip->locallb_get_member_v +2( $bigip_host, $pool ); if ( !$membershref ){ printError("Failed to find mem +bers for $pool"); } else { # if ( !$membershref ); print '<UL>'; + # Pool Members foreach my $member ( sort keys + %{$membershref} ) { print li( "'$member', $membershref->{$member}->{'address'}:$membershref->{$membe +r}->{'port'}, enabled:$membe +rshref->{$member}->{'enabled'}, availability:$memb ershref->{$member}->{'availability'}" ); } print '</UL>';

But the above code produce below output

'HASH(0xbafd04)', :, enabled:, availability:

Replies are listed 'Best First'.
Re^3: Complicated datastructre and after merging giving numeric value need help!!
by Corion (Patriarch) on Oct 24, 2013 at 08:34 UTC

    Your code in sub locallb_get_member_v2 { constructs a weird data structure and contains stuff that makes it hard to believe this is meant as such:

    $members{ $status->{'address'} = $member->{'port'}};

    Are you sure that this code is intended as such? Did you maybe mean the following? Note the placement of curly braces

    $members{ $status->{'address'}} = $member->{'port'};

    Also, are you using the strict pragma? I can't find where you declare $status, but you use it in the next line:

    $members{ $status}->{'enabled'} = $ENABLED_STATUS_MAP->{ $status->{' +enabled_status'} }

    If your problem is that you are unclear about where parentheses go when assigning things to hashes, I recommend using intermediate variables to store the elements and use sequences of very simple assigments. What key in %members did you want to assign to? $members{ $status } or $members{ $status->{'enabled'} }?

    I recommend restructuring all your hash assignments like the following structure:

    # Restructure the following line # $members{ $status}->{'enabled'} = $ENABLED_STATUS_MAP->{ $status-> +{'enabled_status'} } # ... into lines that end up $members{ $key }= $value; my $key= $status; my $value= $ENABLED_STATUS_MAP->{ $status->{'enabled_status'} }; warn "Assigning '$key'='$value' in results"; $members{ $key }= $value;

    If you read your code like that, it seems highly unlikely to me that you really meant that. Maybe you meant the following?

    # $members{ 'enabled' }= $ENABLED_STATUS_MAP->{ $status->{'enabled_s +tatus'} } # ... into lines that end up $members{ $key }= $value; my $key= 'enabled'; my $value= $ENABLED_STATUS_MAP->{ $status->{'enabled_status'} }; warn "Assigning '$key'='$value' in results"; $members{ $key }= $value;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1059360]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-24 04:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found