Hello again gbwien,
Try something like this:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; sub callForwardingsCF { my ($inFile, $outFile) = @_; open (my $fhIn, '<', $inFile) or die "Can not open .'".$inFile."'.: $!"; open (my $fhOut, '>', $outFile) or die "Can not open .'".$outFile."'.: $!"; my %hash = (); my %finalHash = (); my $count = 0; while (<$fhIn>) { chomp; next if (/<BEGINFILE>|<ENDFILE>/); if (/<SUBBEGIN/) { $count = 1; } elsif (/<SUBEND/) { $count = 0; } elsif ($count) { my @tmp = split /=/; chop $tmp[1]; if (/MSISDN/) { $hash{MSISDN} = $tmp[1]; } elsif (/ODBIC/) { $hash{ODBIC} = $tmp[1]; } elsif (/ODBOC/) { $hash{ODBOC} = $tmp[1]; } elsif (/CF/) { my @cf = split /-/, $tmp[1]; if (index($tmp[1], 'CFU-TS10-ACT') != -1){ $hash{'CF'}{$cf[0]} = $tmp[1]; } elsif ((index($tmp[1], 'CFB-TS10-ACT') != -1)){ $hash{'CF'}{$cf[0]} = $tmp[1]; } } } if ($count == 0) { # we finished the first matching part %finalHash = (%finalHash, %hash); if ( exists $hash{MSISDN} and exists $hash{CF}{CFU} and exists $hash{CF}{CFB} ) { print $fhOut Dumper( \%hash ); } # remove current information prepare for next part of lines delete $hash{MSISDN}; delete $hash{CF}; } } close ($fhIn) or warn "Can not close .'".$inFile."'.: $!"; close ($fhOut) or warn "Can not close .'".$outFile."'.: $!"; return \%finalHash; } print Dumper callForwardingsCF('in.txt', 'out.txt'); __END__ $ perl test.pl $VAR1 = { 'CF' => { 'CFU' => 'CFU-TS10-ACT-NONE-YES-NO-NONE-YES-65535- +YES-YES-NO-NO-NO-NO-NO-NO-NO-NO', 'CFB' => 'CFB-TS10-ACT-NONE-YES-NO-NONE-YES-65535- +YES-YES-NO-NO-NO-NO-NO-NO-NO-NO' }, 'MSISDN' => '1234567890' }; $ cat out.txt $VAR1 = { 'CF' => { 'CFU' => 'CFU-TS10-ACT-NONE-YES-NO-NONE-YES-65535- +YES-YES-NO-NO-NO-NO-NO-NO-NO-NO', 'CFB' => 'CFB-TS10-ACT-NONE-YES-NO-NONE-YES-65535- +YES-YES-NO-NO-NO-NO-NO-NO-NO-NO' }, 'MSISDN' => '1234567890' };
Since you did not provide us with more than one subsection of your file or desired output I am not able to help you more than that.
Hope this helps, BR.
In reply to Re^3: Check multiple lines exist in a record
by thanos1983
in thread Check multiple lines exist in a record
by gbwien
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |