Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

extact nested values

by rajivreddy (Initiate)
on Mar 04, 2013 at 16:32 UTC ( #1021673=perlquestion: print w/ replies, xml ) Need Help??
rajivreddy has asked for the wisdom of the Perl Monks concerning the following question:

$VAR1 = { 'press-release' => [ { 'PromoModuleTwo' => [ { 'LeftColoumn' + => [ + { + 'Heading' => [ + ' xxxxxx' + ], + 'PromoLink' => [ + 'XXXXXX' + ], + 'SubHeading' => [ + 'XXXXXX.' + ], + 'PromoText' => [ + 'LEARN MORE2' + ], + 'PromoImage' => [ + 'XXXXXX/' + ] + } + ], 'ModuleBackgr +oundImage' => [ + 'XXXXXX' + ], 'ColorCode' = +> [ + 'YELLOW' + ], 'RightColoumn +' => [ + { + 'Tabs' => [ + { + 'Links' => [ + { + 'AssetLink' => [ + 'XXXXXX' + ], + 'AssetTitle' => [ + 'XXXXXX' + ], + 'AssetSource' => [ + 'xxxxxxx' + ] + }, + { + 'AssetLink' => [ + 'xxxxxx' + ], + 'AssetTitle' => [ + 'xxxxx' + ], + 'AssetSource' => [ + 'xxxxxx' + ] + } + ], + 'TabName' => [ + 'NEWS' + ] + }, + { + 'Links' => [ + { + 'AssetLink' => [ + 'XXXXXX' + ], + 'AssetTitle' => [ + 'XXXXXXk' + ], + 'AssetSource' => [ + 'XXXXXX' + ] + }, + { + 'AssetLink' => [ + 'XXXXXX/' + ], + 'AssetTitle' => [ + 'xxxxxxx' + ], + 'AssetSource' => [ + 'XXXXXX' + ] + }, + { + 'AssetLink' => [ + 'XXXXXXx' + ], + 'AssetTitle' => [ + 'XXXXXX' + ], + 'AssetSource' => [ + 'XXXXXX' + ] + }, + { + 'AssetLink' => [ + 'XXXXXX' + ], + 'AssetTitle' => [ + 'XXXXXX' + ], + 'AssetSource' => [ + 'XXXXXX' + ] + } + ], + 'TabName' => [ + 'WHITEPAPERS' + ] + } + ] + } + ] } ], 'PromoModuleOne' => [ { 'LeftColoumn' + => [ + { + 'PromoLink' => [ + 'XXXXXX' + ], + 'HeadingImage' => [ + 'XXXXXX' + ], + 'PromoText' => [ + 'LEARN MORE 1' + ], + 'PromoImage' => [ + 'XXXXXX/XXXXXX.jpg' + ] + } + ], 'ModuleBackgr +oundImage' => [ + 'XXXXXX/section_bg.png' + ], 'ColorCode' = +> [ + 'MAROON' + ], 'RightColoumn +' => [ + { + 'Tabs' => [ + { + 'Links' => [ + { + 'AssetLink' => [ + 'XXXXXX' + ], + 'AssetTitle' => [ + 'XXXXXX' + ], + 'AssetSource' => [ + 'XXXXXX' + ] + }, + { + 'AssetLink' => [ + 'XXXXXX' + ], + 'AssetTitle' => [ + 'XXXXXX Ax' + ], + 'AssetSource' => [ + 'xxxxxx' + ] + }, + { + 'AssetLink' => [ + 'XXXXXX' + ], + 'AssetTitle' => [ + 'XXXXXX' + ], + 'AssetSource' => [ + 'XXXXXX' + ] + } + ], + 'TabName' => [ + 'NEWS' + ] + }, + { + 'Links' => [ + { + 'AssetLink' => [ + 'XXXXXX' + ], + 'AssetTitle' => [ + 'XXXXXX' + ], + 'AssetSource' => [ + 'NETWORK TES +T' + ] + }, + { + 'AssetLink' => [ + 'XXXXXX/' + ], + 'AssetTitle' => [ + 'XXXXXX' + ], + 'AssetSource' => [ + 'XXXXXX' + ] + }, + { + 'AssetLink' => [ + 'XXXXXX' + ], + 'AssetTitle' => [ + 'xxxxx' + ], + 'AssetSource' => [ + 'xxxxx' + ] + }, + { + 'AssetLink' => [ + 'XXXXXX' + ], + 'AssetTitle' => [ + 'XXXXXX' + ], + 'AssetSource' => [ + 'NETWORK TES +T' + ] + } + ], + 'TabName' => [ + 'WHITEPAPERS' + ] + } + ] + } + ] } ], 'modulemiddle' => [ { 'BackgroundImag +e' => [ + {} + ], 'Heading' => [ +'xxxxxxe?' ], 'SupplementalIm +age' => [ + 'XXXXXX' + ], 'ColorCode' => +[ + 'BLACK' +], 'LinkURL' => [ +'XXXXXX' ], 'RightColoumnIm +age' => [ + 'XXXXXX' + ], 'SubHeading' => + [ + 'xxxxxxx.' + ] } ], 'hero' => [ { 'videos' => [ { 'VideoI +mage' => [ + 'XXXXXX/hero_1_a1.jpg' + ], 'VideoU +RL' => [ + 'XXXXXX' + ], 'VideoT +itle' => [ + 'xxxxx.' + ] }, { 'VideoI +mage' => [ + 'XXXXXX/hero_1_a2.jpg' + ], 'VideoU +RL' => [ + 'XXXXXX' + ], 'VideoT +itle' => [ + 'xxxxx' + ] }, { 'VideoI +mage' => [ + 'XXXXXX/hero_1_a3.jpg' + ], 'VideoU +RL' => [ + 'XXXXXX' + ], 'VideoT +itle' => [ + 'xxxxx' + ] }, { 'VideoI +mage' => [ + 'XXXXXX/' + ], 'VideoU +RL' => [ + 'XXXXXX' + ], 'VideoT +itle' => [ + 'xxxxx' + ] } ], 'Heading' => [ 'xxxxx' ], 'SupplementalImage' => +[ + 'XXXXXX/icon_arrow_dark.png' +], 'SubHeading' => [ 'xxxx +xx' ], 'HeroImage' => [ 'XXXXX +X/hero_1.jpg' ] } ], 'meta' => [ { 'keywords' => [ {} ], 'summary' => [ 'XXXXXX' ], 'locale' => [ 'en_US' ], 'title' => [ 'XXXXXX' ], 'description' => [ {} ] } ] } ] };
Hi monks need to extract the values of tab name and the values of the elements in between the link nodes for promomdoule1 and promomodule2.I tried a couple of ways but doesn't seem to work please help

Comment on extact nested values
Download Code
Re: extact nested values
by blue_cowdawg (Prior) on Mar 04, 2013 at 16:59 UTC
        I tried a couple of ways but doesn't seem to work please help

    Show us one of those ways...


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: extact nested values
by McA (Deacon) on Mar 04, 2013 at 17:24 UTC

    Hi,

    to be honest: I don't see the problem:

    print $VAR1->{'press-release'}->[0]->{'PromoModuleTwo'}->[0]->{'RightC +oloumn'}->[0]->{'Tabs'}->[0]->{'TabName'}->[0], "\n"; print $VAR1->{'press-release'}->[0]->{'PromoModuleTwo'}->[0]->{'RightC +oloumn'}->[0]->{'Tabs'}->[1]->{'TabName'}->[0], "\n"; print Dumper($VAR1->{'press-release'}->[0]->{'PromoModuleTwo'}->[0]->{ +'RightColoumn'}->[0]->{'Tabs'}->[0]->{'Links'}), "\n"; print Dumper($VAR1->{'press-release'}->[0]->{'PromoModuleTwo'}->[0]->{ +'RightColoumn'}->[0]->{'Tabs'}->[1]->{'Links'}), "\n"; print Dumper($VAR1->{'press-release'}->[0]->{'PromoModuleOne'}->[0]->{ +'RightColoumn'}->[0]->{'Tabs'}->[0]->{'Links'}), "\n"; print Dumper($VAR1->{'press-release'}->[0]->{'PromoModuleOne'}->[0]->{ +'RightColoumn'}->[0]->{'Tabs'}->[1]->{'Links'}), "\n";

    Have I missed something with the problem description?

    Best regards
    McA

      Hi MCA thanks for the reply but my problem is to print the values of the child elements of the link nodes iteratively and
      print $VAR1->{'press-release'}->[0]->{'PromoModuleTwo'}->[0]->{'RightC +oloumn'}->[0]->{'Tabs'}->[0]->{'TabName'}->[0], "\n";
      isn't printing anything

        Do you know how to iterate over a perl list?

        As the dumper output shows: The output of $VAR1->{'press-release'}->[0]->{'PromoModuleOne'}->[0]->{'RightColoumn'}->[0]->{'Tabs'}->[1]->{'Links'} is a list ref.

        So the following

        my $list_ref = $VAR1->{'press-release'}->[0]->{'PromoModuleOne'}->[0]- +>{'RightColoumn'}->[0]->{'Tabs'}->[1]->{'Links'}; foreach my $elem (@$list_ref) { print "Element by element", Dumper($elem), "\n"; }
        iterates over the list and you get every element which is by the way also a nested object. But with my solution shown it should be worth of a little transfer to address the child elements in every $elem. If this is not true then you have to learn some basics.

        Best regards
        McA

Re: extact nested values
by Anonymous Monk on Mar 04, 2013 at 22:51 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2014-07-12 01:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (238 votes), past polls