Hello again gbwien,
I was under the impression that you want the opposite output. This should do what you want:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use feature 'say'; open (my $fhIn, '<', "in.txt") or die "Can not open 'in.txt': $!"; open (my $fhOut, '>', "out.txt") or die "Can not open 'out.txt': $!"; my %hash = (); 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], 'CFB-ALL-PROV-NONE') != -1){ $hash{'CF'}{$cf[0]} = $tmp[1]; } else { $hash{'CF'}{$cf[0]} = 'CfbNotSet'; } if (index($tmp[1], 'CFU-ALL-PROV-NONE') != -1){ $hash{'CF'}{$cf[0]} = $tmp[1]; } else { $hash{'CF'}{$cf[0]} = 'CfuNotSet'; } if (index($tmp[1], 'CFNRY-ALL-PROV-NONE') != -1){ $hash{'CF'}{$cf[0]} = $tmp[1]; } else { $hash{'CF'}{$cf[0]} = 'CfnrnyNotSet'; } if (index($tmp[1], 'CFNRC-ALL-PROV-NONE') != -1){ $hash{'CF'}{$cf[0]} = $tmp[1]; } else { $hash{'CF'}{$cf[0]} = 'CfnrncNotSet'; } $hash{'CF'}{$cf[0]} = $tmp[1]; } } if ($count == 0) { print Dumper \%hash; if (exists $hash{MSISDN}) { say $fhOut "Update Command <".$hash{MSISDN}.">,".$hash{ODBIC}. +",".$hash{ODBOC}.""; } else { say $fhOut "Update Command MSISDN=notSet,".$hash{ODBIC}.",".$h +ash{ODBOC}.""; } delete $hash{MSISDN}; delete $hash{ODBIC}; delete $hash{ODBOC}; delete $hash{CF}; } } close ($fhIn) or warn "Could not close 'in.txt': $!"; close ($fhOut) or warn "Could not close 'out.txt': $!"; __END__ $ perl test.pl $VAR1 = { 'ODBIC' => 'BAIC', 'CF' => { 'CFU' => 'CFU-ALL-PROV-NONE-YES-NO-NONE-YES-65535- +NO-NO-NO-NO-NO-NO-NO-NO-NO-NO', 'CFD' => 'CFD-TS10-ACT-9112345678-YES-YES-25-YES-6 +5535-YES-YES-NO-NO-NO-YES-YES-YES-YES-NO', 'CFB' => 'CFB-ALL-PROV-NONE-YES-YES-NONE-YES-65535 +-NO-NO-NO-NO-NO-NO-NO-NO-NO-NO', 'CFNRC' => 'CFNRC-ALL-PROV-NONE-YES-NO-NONE-YES-65 +535-NO-NO-NO-NO-NO-NO-NO-NO-NO-NO', 'CFNRY' => 'CFNRY-ALL-PROV-NONE-YES-YES-NONE-YES-6 +5535-NO-NO-NO-NO-NO-NO-NO-NO-NO-NO' }, 'MSISDN' => '4411287879987', 'ODBOC' => 'BAOC' };
Hope this helps. BR / Thanos
In reply to Re^5: Grouped Regular Expression not set assign default value
by thanos1983
in thread Grouped Regular Expression not set assign default value
by gbwien
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |