im still beginner with perl , here im trying to loop over $struct->{'transferBatch'}->{'networkInfo'}; and its dump looks like :
$VAR1 = {
'utcTimeOffsetInfo' => [
{
'utcTimeOffset' => '+0100',
'utcTimeOffsetCode' => 0
}
],
'recEntityInfo' => [
{
'recEntityId' => '87.238.128.37',
'recEntityType' => 2,
'recEntityCode' => 0
},
{
'recEntityCode' => 1,
'recEntityType' => 2,
'recEntityId' => '213.233.130.201'
},
{
'recEntityId' => '353876999524',
'recEntityCode' => 1,
'recEntityType' => 1
},
{
'recEntityCode' => 3,
'recEntityType' => 1,
'recEntityId' => '353876999523'
}
]
};
i just want to get the recEntityCode where recEntityType = 2 and store it in veriable $recEntityCode_2 and same thing for recEntityType = 1 $recEntityCode_1 , only one value for each on of them just first catch then break out the loop
#!/usr/bin/perl -w
use strict;
use warnings;
use TAP3::Tap3edit;
use Data::Dumper;
printDir(".");
sub printDir{
opendir(DIR, $_[0]);
my @files;
my @dirs;
(@files) = readdir(DIR);
foreach my $file (@files) {
if (-f $file and substr($file,0,2) eq "CD") {
my $tap3 = TAP3::Tap3edit->new;
my $tap_file = $file;
$tap3->decode($tap_file) or die $tap3->error;
my $struct=$tap3->structure;
my $Tracker = $struct->{'transferBatch'};
if (defined $Tracker){
my $rectag = $struct->{'transferBatch'}->{'networkInfo'}->{'recEntityInfo'};
$count_1=0;
$count_2=0
foreach my $rectag1( @{$rectag} )
{
if ($rectag1->{'recEntityType'} && int($rectag1->{'recEntityType'}) == 2){
$var1_recEntityType = $rectag1->{'recEntityCode'}
$count_1 = $count_1 + 1;
}
if ($rectag1->{'recEntityType'} && int($rectag1->{'recEntityType'}) == 1){
$var1_recEntityType = $rectag1->{'recEntityCode'}
$count_2 = $count_2 + 1;
}
if ($count_1 = 1 && $count_2 = 1)
{
break;
}
}
print $recEntityCode_2;
print$recEntityCode_1;
$tap3->encode("$tap_file") or die $tap3->error;
}
}
}
closedir(DIR);
}
breakstatement in Perl. Also you are not showing us the full code, or you don't haveuse strictanduse warnings. There might be other typos in your code. What is the output you are getting?$count_1 = 1is probably supposed to be$count_1 == 1, etclast) does not requireuse feature 'switch'oruse v5.10@ikegami) for them to get notified if it's not tehir post to which you are replying.print Dumper \$t;should have beenprint Dumper $t. That explains the extra `` in the output (which I removed).