in reply to Re: Usage of hashes with hashes when mulitple values are present
in thread Usage of hashes with hashes when mulitple values are present

Hi , Please find this piece of code as follows ::
# Get the list of cells, which has same frequency and SC Id # $t = $w{$_}{frequency} .':'. $w{$_}{sc}; push(@{$w{$t}{cells}}, $_);
. Here w is a hash variable . for each cell we will be retrieving its corresponding frequency and sc value in following format repectively :
$w{$_}{frequency} and $w{$_}{sc}
The above piece of code will collect all the cells which fall in that frequency and sc value .. SO when we give data dumper we will get as follows ::
'-1:130' => { 'cells' => [ 'SubNetwork=ONRM_ROOT_MO_R,SubNet +work=RNC12,MeContext=RNC12,ManagedElement=1,RncFunction=1,UtranCell=R +NC12-8-2' 'SubNetwork=ONRM_ROOT_MO_R,SubNetwork=RNC12,MeContext=RNC12,ManagedEle +ment=1,RncFunction=1,UtranCell=RNC12-8-8' ] },
Please let me know how to retrieve the values taht are in array .

Replies are listed 'Best First'.
Re^3: Usage of hashes with hashes when mulitple values are present
by lune (Pilgrim) on Dec 02, 2013 at 11:05 UTC
    It is hard to follow you, as you omit certain information, that would make it much easiear to answer your question.

    You should just post a runnable piece of complete code, that shwow your problem. Please read ?node_id=510718

    As you just want to know how to *access* the data, why bother about the way you *create* the data structure? Here, I just initialized a hash with the data you provided. Then I can access the elements of the arrayref:

    #!/usr/bin/perl -w use strict; use Data::Dumper; my %w = ( '-1:130' => { 'cells' => [ 'SubNetwork=ONRM_ROOT_MO_R,SubNetwork=RNC12,MeContext=RNC1 +2,ManagedElement=1,RncFunction=1,UtranCell=RNC12-8-2', 'SubNetwork=ONRM_ROOT_MO_R,SubNetwork=RNC12,MeContext=RNC1 +2,ManagedElement=1,RncFunction=1,UtranCell=RNC12-8-8' ], }, ); #print Dumper(\%w); # access one element by index: first = 0 print "Element 0: " . $w{'-1:130'}{'cells'}->[0] . "\n"; print "\n"; # access all available in a foreach loop foreach my $element (@{$w{'-1:130'}{'cells'}}) { print $element . "\n"; }

      Thanks lune and all . It was helpful for me to understand the usage of hash .