Perl deferencing from Hash of Array Structure -


i have hash of array , hash looks follow:

$var1 = \{            'abc' => {                        'def' => 'workset',                        'products' => [                                        {                                          'prodtype' => 'dell',                                          'product' => 'powerconnect-5600'                                        },                                        {                                          'prodtype' => 'dell',                                          'product' => 'r-720'                                        },                                        {                                          'prodtype' => 'dell',                                          'product' => 'r-920'                                        }                                      ]                      },         '123' => {                         '456' => 'workset',                         'products' => [                                         {                                           'prodtype' => 'dell',                                           'product' => '210'                                         },                                         {                                           'prodtype' => 'dell',                                           'product' => 'tz-200'                                         },                                         {                                           'prodtype' => 'dell',                                           'product' => 'tz-200'                                         },                                        ]           }  } 

i have such that:

  branch: workset   build number: abc   product : dell producttype : powerconnect-5600   product : dell producttypr : r-720   product : dell producttype : r-920 

it should same hash value 123 too.

i know deference above hash individually, finding difficult in loop.

please give me guidance.

fyi, have listed above hash using data:dumper perl module.

        thought , tried not getting required answer in loops:    @unique = uniq @version;   foreach $version(@ unique){   $i=0;   print "$list->{$version}{branch}\n";   print "$list->{$version}->{products}->[$i]->{product}\n";   $i=$i+1;   } @unique = qw (abc,123) 

however, realize not data structure. providing example of way go different approach.

use strict; use warnings; use feature 'say';  $h = {       abc => {           workset => {                         dell => [                                   'powerconnect-5600',                                   'r-270',                                   'r-920',                                 ],                      },              },       123 => {           workset => {                        dell => [                                  '210',                                  'tz-200',                                ],                      },              }, };  $k ( keys %$h ) {    $j ( keys %$h->{$k} ) {       $prod ( keys %$h->{$k}{$j} ) {          "branch: $j";          "build number: $k";          "product : $prod producttype : " . $_ @{ $h->{$k}{$j}{$prod} };       }    } } 

output:

branch: workset build number: 123 product : dell producttype : 210 product : dell producttype : tz-200  branch: workset build number: abc product : dell producttype : powerconnect-5600 product : dell producttype : r-270 product : dell producttype : r-920 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -