anadem has asked for the wisdom of the Perl Monks concerning the following question:
#--------------------- component -- targetver -- Arr -- datahash # # $ComponentData = { # 'key_A' => { # '6.0' => [ # { # 'FILENAME' => 'fi +lename', # 'VERSION' => 've +rsion'; # ooo # }, # ooo # ], # ooo # }, # ooo # } # # where ooo represents potential repetition # my %ComponentData; sub store_data { my $parmref = shift; # input parameter is a hash ref my $component = $parmref->{COMPONENT}; my $tgtver = $parmref->{TGTVER}; my $version = $parmref->{VERSION}; my $file = $parmref->{FILENAME}; # store data $ComponentData{$component}->{$tgtver} = [] unless exists $Componen +tData{$component}->{$tgtver}; my $href = {}; $href->{VERSION} = $version; if( $file ){ $href->{FILENAME} = $file }; push @{$ComponentData{$component}->{$tgtver}}, $href; } sub oldstore_data { # store a data hash $ComponentData{$component}->{$targetver} = [] unless exists $Compo +nentData{$component}->{$targetver}; my $href = {}; if( $file ){ $href->{FILENAME} = $file }; if( $checksum ){ $href->{CHECKSUM} = $checksum }; # etc push @{$ComponentData{$component}->{$targetver}}, $href; return; } # show all the data sub show_all_data { foreach my $comp ( sort keys %ComponentData ) { print "- - - - -\n"; print "component:$comp\n"; foreach my $tgtver ( sort keys %{ $ComponentData{$comp}} ) { print " target:$tgtver\n"; for my $href (@{ $ComponentData{$comp}{$tgtver} }) { print " version:", $href->{VERSION},"\n"; if( $href->{FILENAME} ) { print " file: ", $href->{FILENAME},"\n"; }else{ print " file: undefined\n "; } } print "\n"; } } } while (<DATA>) { chomp; $_ =~ s/ +//g; my ($comp, $tgtver, $version, $file ) = split /\|/; #print "comp=$comp, tgtver=$tgtver, version=$version, file=$file;\ +n"; my $href = {}; $href->{COMPONENT} = $comp; $href->{TGTVER} = $tgtver; $href->{VERSION} = $version; if( $file ){ $href->{FILENAME} = $file; } store_data( $href ); } show_all_data ; # is there a nice way to get the value I want here, without foreach? foreach my $xstgt ( sort keys %{ $ComponentData{ "WinBinary" }} ) { my $specialsource = ${@{ $ComponentData{ "WinBinary" }{$xstgt}}[0] +}{FILENAME}; print "what I want is $specialsource\n" } print "done/n"; # component target version sourcefile __DATA__ WinBinary | 4.0 | 7.8.9.123 | winbinsrc NetBinary | 5.0 | 10.1.2.34 | netbinsrc SupplementalPack | 6.0 | 1.6.0 SupplementalPack | 6.1 | 1.6.0 Hotfix | 6.0 | NULL | hotsource01 Hotfix | 6.0 | NULL | hotsource02 Hotfix | 6.1 | NULL | hotsource03 Hotfix | 6.1 | NULL | hotsource04
|
|---|