Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Grouped Regular Expression not set assign default value

by Laurent_R (Canon)
on Feb 20, 2018 at 18:24 UTC ( [id://1209605]=note: print w/replies, xml ) Need Help??


in reply to Grouped Regular Expression not set assign default value

Hi gbwien,

your code is based on a suggestion I made a few days ago in another thread that you opened (http://www.perlmonks.org/?node_id=1209051).

But, in that post, based on the data that you had originally shown, I was using an MSISDN line to detect the beginning of the new record block. You're now showing data where there is not always a line with an MSISDN. So you need to use something else to detect the beginning of a record. See my solution posted today (http://www.perlmonks.org/?node_id=1209603), where <SUBEND is used to detect the end of a block.

As I already pointed out in that previous thread, you're using too many parentheses in your regex, making your life more difficult than it needs to be.

For example, replace:

if (/^(\t*MSISDN=(\d+));/) {
with:
if (/^\t*MSISDN=(\d+);/) {
and use $1 rather than $2.

Replies are listed 'Best First'.
Re^2: Grouped Regular Expression not set assign default value
by gbwien (Sexton) on Feb 21, 2018 at 12:04 UTC

    Hi Laurent_R

    Thanks again for your help. The code I wrote in http://www.perlmonks.org/?node_id=1209586 is based on the same problem but I made the mistake of not using a consistent input file across posts. I am still working on building up the contents of the input file with additional populated data and I thought it was best to use something like <SUBBEGIN and <SUBEND. Additional populated data below to be decided is represented by ..... and may appear anywhere in the file,but I don't need to worry about this. For the output file I am only interested in extracting and checking the fields MSISDN, CB, CF, ODB based on what is to the right of the equals sign. Also one important point the data may appear in any order.

    My question in the last post was to try to understand how to check if the line MSISDN is not found . I thought I could apply this knowledge to lines CB, CF and ODB too and wirte something similar e.g. CB=BAOC-ALL-PROV; not found write CBBocallProvNotSet, CF=CFU-ALL-PROV-NONE not found write CFUallProvNotSet. Again very sorry about the confusion, I will try to be more concise on the site going forward

    Example record in the input file with all considered values we spoke about

    <SUBBEGIN IMSI=21111111111111; MSISDN=413333333331; ..... ... 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-N +O-NO-NO; CF=CFB-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO- +NO-NO-NO; CF=CFNRY-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-N +O-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

    I wrote the following based on your code

    #!/usr/bin/perl use strict; use warnings; use feature 'say'; my $HSSIN='D:\testproject\HSS-export.txt'; my $ofile = 'D:\testproject\HSS-output.txt'; my $add; my $MSISDN; open (INFILE, $HSSIN) or die "Can't open input file"; open (OUTFILE,"> $ofile" ) or die "Cant open file"; my $line; while (<INFILE>) { if (/<SUBEND/) { print OUTFILE "$line\n"; $line = "MSISDN=0"; } $line = $1 if /^\s*MSISDN=(\d+);/; #if (/^\t*MSISDN=(\d+);/) { #find MSISDN in file global search # print OUTFILE "processSingle Update Command MKEY <parameter n +ame> $line, \n" if defined $line; # $line = "<$1>"; #group 1 #blockings if (/\t*CB=([\w-]+?);/) { $add = $1; $line .= ",$add"; } #call forwardings if (/\t*CF=([\w-]+?-(?:NONE|\d+))/ and (!/(\t*CF=CFD-[\w-]+?-\d+)/ +)) { $add = $1; #the entire of group 1 above, next search the line $add =~ s/\t//g; $add =~ s/(91)(\d+)?/$2/; #remove 91 from $1 above CFD-TS10-AC +T-91436903000 #$add =~ s/\b436903000/43660303060/; $add =~ s/(\d+)$/1\/1\/1\/$1/; $add =~ s/NONE/1\/1\/1\/0/; $line .= ",$add"; } #change CFD to 43660303060 for voicemail if (/(\t*CF=(CFD-[\w-]+?-\d+))/ ) { $add = $2; $add =~ s/\t//g; #$add =~ s/(91)(\d+)?/1\/1\/1\/$2/; #remove 91 from $2 above $add =~ s/\b91436903000/1\/1\/1\/43660303060/; $add =~ m/(?:CFD-[\w].*-)(\d)\/(\d)\/(\d)\/(\d*)/; $line .= ",$add"; } #odb stuff #if ($_ =~ m/\t*ODBIC=([\w-]+?\w.*);/) if (/\t*ODBIC=([\w]+?\w.*);/) { #$add = "mappedBICVALUE"; $add = $1, $line .= ",$add"; } if (/\t*ODBOC=([\w]+?\w.*);/) { $add = $1; $line .= ",$add"; } if (/\t*ODBROAM=([\w]+?\w.*);/) { $add = $1; $line .= ",$add"; } if (/\t*ODBPRC=([\w]+?\w.*);/) { $add = $1; $line .= ",$add"; } if (/\t*ODBPLMN=([\w]+?\w.*);/) { $add = $1; $line .= ",$add"; } if (/\t*ODBPOS=([\w]+?\w.*);/) { $add = $1; $line .= ",$add"; } if (/\t*ODBECT=([\w]+?\w.*);/) { $add = $1; $line .= ",$add"; } if (/\t*ODBDECT=([\w]+?\w.*);/) { $add = $1; $line .= ",$add"; } if (/\t*ODBMECT=([\w]+?\w.*);/) { $add = $1; $line .= ",$add"; } if (/\t*ODBPREMSMS=([\w]+?\w.*);/) { $add = $1; $line .= ",$add"; } if (/\t*ODBADULTSMS=([\w]+?\w.*);/) { $add = "$1"; $line .= ",$add"; } #if (/\t*ODB(\w+)?=([\w-]+?\w.*);/) #{ # $add = $2; #$add =~ s/\t//g; # $line .= ",$add"; #} } #print OUTFILE "processSingle Update Command MKEY <parameter name> $li +ne, \n"; close INFILE; close OUTFILE;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1209605]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-23 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found