in reply to Re^2: Grouped Regular Expression not set assign default value
in thread Grouped Regular Expression not set assign default value
Hello again gbwien,
I am not 100% sure what is the expected output from your description. I took a guess and I put together an example based on the new input and what I think you mean.
Having said that I think the only modifications that you need to add is:
#!/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>/); 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]} = 'CfbNotSet'; } elsif (index($tmp[1], 'CFU-ALL-PROV-NONE') != -1){ $hash{'CF'}{$cf[0]} = 'CfuNotSet'; } elsif (index($tmp[1], 'CFNRY-ALL-PROV-NONE') != -1){ $hash{'CF'}{$cf[0]} = 'CfnrnyNotSet'; } elsif (index($tmp[1], 'CFNRC-ALL-PROV-NONE') != -1){ $hash{'CF'}{$cf[0]} = 'CfnrncNotSet'; } else { $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 = { 'MSISDN' => '431234567893', 'ODBOC' => 'BAOC', 'ODBIC' => 'BAIC', 'CF' => { 'CFNRC' => 'CfnrncNotSet', 'CFB' => 'CfbNotSet', 'CFD' => 'CFD-TS10-ACT-91436903000-YES-YES-25-YES- +65535-YES-YES-NO-NO-NO-YES-YES-YES-YES-NO;', 'CFNRY' => 'CfnrnyNotSet', 'CFU' => 'CfuNotSet' } }; $VAR1 = { 'ODBIC' => 'BICCROSSDOMESTIC', 'ODBOC' => 'BAOC', 'MSISDN' => '431234567899', 'CF' => { 'CFNRY' => 'CfnrnyNotSet', 'CFU' => 'CFU-TS10-ACT-914369050045021-YES-NO-NONE +-YES-65535-YES-YES-NO-NO-NO-NO-NO-NO-NO-NO', 'CFB' => 'CfbNotSet', 'CFNRC' => 'CfnrncNotSet', 'CFD' => 'CFD-TS10-REG-91436903000-YES-YES-25-YES- +65535-YES-YES-NO-NO-NO-YES-YES-YES-YES-NO' } }; $ cat out.txt Update Command <431234567893>,BAIC,BAOC Update Command <431234567899>,BICCROSSDOMESTIC,BAOC
I have not update the concatenation of the string output since I do not know what is the actual output that you are looking for.
In case that this is not the expected way the string should behave, provide an desired output sample so I can understand approximately based on input which fields you want to keep and which you want to skip.
Hope this helps, BR.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Grouped Regular Expression not set assign default value
by gbwien (Sexton) on Feb 23, 2018 at 12:16 UTC | |
by thanos1983 (Parson) on Feb 23, 2018 at 15:42 UTC | |
by Anonymous Monk on Feb 23, 2018 at 19:49 UTC |