Hi thanos1983 Thank you for your help, I extended your solution to check for these fields CF and ODB fields which I output to a comma separated file when set and not set. It works fine except for CF fields, I think this is because these lines are not unique in the file. For CF lines example I would like to set CfuNotSet if the line CFU-ALL-PROV-NONE is not found, CFbNoSet if the line CFB-ALL-PROV-NONE is not found and so on. Eventually I would also like to check for CB fields. I have done this without a hash with the help from Laurent_R but I would like to learn your solution too

This piece of code seems ok code

#build up the hash CF if (/CF/){ $hash{CF} = $tmp[1]; #say $hash{CF}; }

I think the problem is here

#PROBLEM CODE check CF fields need to accommodate for multiple CF l +ines if (exists $hash{CF}) { $add = $hash{CF}; $line .= ",$add"; }
<BEGINFILE> <SUBBEGIN IMSI=11111111111111; MSISDN=431234567893; CB=BAOC-ALL-PROV; CB=BOIC-ALL-PROV; CB=BOICEXHC-ALL-PROV; CB=BICROAM-ALL-PROV; IMEISV=4565676567576576; CW=CW-ALL-PROV; CF=CFU-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-NO +-NO-NO; CF=CFB-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-N +O-NO-NO; CF=CFNRY-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO +-NO-NO-NO; CF=CFNRC-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO- +NO-NO-NO; CF=CFD-TS10-ACT-91436903000-YES-YES-25-YES-65535-YES-YES-NO-NO-NO- +YES-YES-YES-YES-NO; ODBIC=BAIC; ODBOC=BAOC; ODBROAM=ODBOHC; ODBPRC=ENTER; ODBPRC=INFO; ODBPLMN=NONE; ODBPOS=NOBPOS-BOTH; ODBECT=OdbAllECT; ODBDECT=YES; ODBMECT=YES; ODBPREMSMS=YES; ODBADULTSMS=YES; <SUBEND <SUBBEGIN IMSI=11111111111133; MSISDN=431234567899; CB=BAOC-ALL-PROV; CB=BOIC-ALL-PROV; CB=BOICEXHC-ALL-PROV; CB=BICROAM-ALL-PROV; CW=CW-ALL-PROV; CF=CFU-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-NO +-NO-NO; CF=CFB-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-N +O-NO-NO; CF=CFNRY-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO +-NO-NO-NO; CF=CFNRC-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO- +NO-NO-NO; CF=CFU-TS10-ACT-914369050045021-YES-NO-NONE-YES-65535-YES-YES-NO-N +O-NO-NO-NO-NO-NO-NO; CF=CFD-TS10-REG-91436903000-YES-YES-25-YES-65535-YES-YES-NO-NO-NO- +YES-YES-YES-YES-NO; ODBIC=BICCROSSDOMESTIC; ODBOC=BAOC; ODBROAM=ODBOH; ODBPRC=INFO; ODBPLMN=PLMN1 ODBPLMN=PLMN3; ODBPOS=NOBPOS-BOTH; ODBECT=OdbAllECT; ODBDECT=YES; ODBMECT=YES; ODBPREMSMS=NO; ODBADULTSMS=YES; <SUBEND

If I understand it correctly you split up the lines of the record based on the equals sign. This seems to work fine until CF entries are encountered

#!/usr/bin/perl use strict; use warnings; use feature 'say'; use Data::Dumper; my $HSSIN='D:\testproject\HSS-export.txt'; my $ofile = 'D:\testproject\HSS-output-withhash.txt'; open (INFILE, $HSSIN) or die "Can't open input file"; open (OUTFILE,"> $ofile" ) or die "Cant open file"; my %hash; my $count = 0; my $add; my $line; while (<INFILE>) { chomp; next if /^<ENDFILE>/; next if /^<BEGINFILE>/; if (/<SUBBEGIN/) { $count = 1; } elsif (/<SUBEND/) { $count = 0; } elsif ($count) { my @tmp = split /=/; chop $tmp[1]; #build up the hash CF if (/CF/){ $hash{CF} = $tmp[1]; #say $hash{CF}; } if (/MSISDN/) { $hash{MSISDN} = $tmp[1]; } if (/ODBIC/) { $hash{ODBIC} = $tmp[1]; } elsif (/ODBOC/) { $hash{ODBOC} = $tmp[1]; } elsif (/ODBROAM/) { $hash{ODBROAM} = $tmp[1]; } } if ($count == 0) { #check MSISDN field if (exists $hash{MSISDN}) { $line = $hash{MSISDN}; #'say OUTFILE $line; #say OUTFILE "Update Command <".$hash{MSISDN}.">,".$hash{ODBIC +}.",".$hash{ODBOC}.",".$hash{ODBROAM}.""; } else { #say OUTFILE "Update Command MSISDN=notSet,".$hash{ODBIC}.",".$ +hash{ODBOC}.""; $line = 'MSISDN=notSet'; } #PROBLEM CODE check CF fields need to accommodate for multiple CF l +ines if (exists $hash{CF}) { $add = $hash{CF}; $line .= ",$add"; } #check ODBIC field if (exists $hash{ODBIC}) { $add = $hash{ODBIC}; $line .= ",$add"; } else { $add = 'ODBICnotSet'; $line .= ",$add"; } #check ODBOC field if (exists $hash{ODBOC}) { $add = $hash{ODBOC}; $line .= ",$add"; } else { $add = 'ODBOC notSet'; $line .= ",$add"; } #check ODBROAM field if (exists $hash{ODBROAM}) { $add = $hash{ODBROAM}; $line .= ",$add"; } else { $add = 'ODBROAM notSet'; $line .= ",$add"; } #check hash for ODBOC->BAOC is not set set it to ODBOC->BAOCnotSet delete $hash{MSISDN}; delete $hash{ODBIC}; delete $hash{ODBOC}; delete $hash{ODBROAM}; delete $hash{CF}; #build up line say OUTFILE $line; } } close INFILE; close OUTFILE;

In reply to Re^2: Grouped Regular Expression not set assign default value by gbwien
in thread Grouped Regular Expression not set assign default value by gbwien

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.