gbwien has asked for the wisdom of the Perl Monks concerning the following question:
Perl typically processes a file line by line but how is it possible to check for multiple lines within a record of a file? My main program reads each line of the input file using a while loop. Within the record below, I need to check if CFU-TS10-ACT and CFB-TS10-ACT are both present :-
<SUBBEGIN IMSI=12345678495452; MSISDN=1234567890; DEFCALL=TS11; CURRENTNAM=BOTH; CAT=COMMON; TBS=TS11&TS12&TS21&TS22; VLRLIST=10; SGSNLIST=10; SMDP=MSC; 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=CFU-TS10-ACT-NONE-YES-NO-NONE-YES-65535-YES-YES-NO-NO-NO-NO-NO- +NO-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=CFB-TS10-ACT-NONE-YES-NO-NONE-YES-65535-YES-YES-NO-NO-NO-NO-NO- +NO-NO-NO; CF=CFD-TS10-REG-9144455778-YES-YES-25-YES-65535-YES-YES-NO-NO-NO-Y +ES-YES-YES-YES-NO; TCSISTATE=YES; OCSISTATE=YES; CONTROL=SUB; WPA=0; GS=HOLD&MPTY&ECT&CLIR&CLIP; CLIRES=TEMPALLOW; CLIPOC=NO; OCSI=10; CFSMS=ACT-10-914366488325207-YES-YES-NO-NO-NO; ARD=PROV; SUBRES=ALLPLMN; IST_ALERT_TIMER=120; IST_ALERT_RESPONSE=2; SUB_AGE=0; MIMSI=240076400029999-ONELIVE-2-2-1-0-0; MIMSI=232191400029999-ONELIVE-1-1-1-0-0; SID=2805158185721065; MCSISTATE=YES; CLRBSG=CLIP-YES-NO-NO-NO-NO; UPLCSLCK=NO; UPLPSLCK=NO; DEFOFAID=10; EPS_PROFILE_ID=1; TGPPAMBRMAXUL=50000000; TGPPAMBRMAXDL=150000000; ARD_EXT=NULL-NULL-NULL-N3GPPNOTALLOWED; FRAUDTPL_ID=10; HLR_INDEX=1; LTEAUTOPROV=NO; PSSER=1-1-10-1-NONE-DYNAMIC-00000000; EPSSER=1-10-10-1-NONE-DYNAMIC-00000000-1; MPS=NO; <SUBEND
In the function callForwardingsCF() below I am using an if statement but I believe I should be using a while loop but I am unclear about how to implement it?
#!/usr/bin/perl use strict; use warnings; use feature 'say'; my $HSSIN='D:\testproject\HSS-export-test-run-small.txt'; my $ofile = 'D:\testproject\HSS-output.txt'; open (INFILE, $HSSIN) or die "Can't open input file"; open (OUTFILE,"> $ofile" ) or die "Cant open file"; my $add; my $MSISDN; my $line; my $CFline; my $CBBOACline; my $CBBOICline; sub callForwardingsCF() { if (/\t*CF=(CFU-TS10-ACT-(NONE|\d+))/ && /\t*CF=(CFB-TS10-ACT-(NONE| +\d+))/) { say "this case is found here ....."; } } # end sub callForwardingsCFD while (<INFILE>) { if (/<SUBEND/) { say "SUBEND found"; #$line = $1 if /^\s*MSISDN=(\d+);/; print OUTFILE "processSingle UpdateCommand GSUB MKEY $line"; print OUTFILE "\n"; } if ($_ =~ /^\t*MSISDN=(\d+);/) { #find MSISDN in file global search say "STARTER MSISDN is $1"; $MSISDN = $1; $add = $1; $line = "$1"; #group 1 } callForwardingsCF(); #callForwardings } close INFILE; close OUTFILE;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Check multiple lines exist in a record
by Your Mother (Archbishop) on Mar 26, 2018 at 15:09 UTC | |
by hippo (Archbishop) on Mar 26, 2018 at 16:11 UTC | |
by Your Mother (Archbishop) on Mar 26, 2018 at 16:15 UTC | |
Re: Check multiple lines exist in a record
by johngg (Canon) on Mar 26, 2018 at 16:02 UTC | |
Re: Check multiple lines exist in a record
by kgoess (Beadle) on Mar 26, 2018 at 16:35 UTC | |
Re: Check multiple lines exist in a record
by choroba (Cardinal) on Mar 26, 2018 at 15:05 UTC | |
Re: Check multiple lines exist in a record
by thanos1983 (Parson) on Mar 26, 2018 at 13:52 UTC | |
by gbwien (Sexton) on Mar 26, 2018 at 14:06 UTC | |
by thanos1983 (Parson) on Mar 26, 2018 at 14:55 UTC | |
Re: Check multiple lines exist in a record
by hippo (Archbishop) on Mar 26, 2018 at 14:12 UTC | |
Re: Check multiple lines exist in a record
by bliako (Abbot) on Mar 26, 2018 at 13:56 UTC | |
Re: Check multiple lines exist in a record
by jeffenstein (Hermit) on Mar 26, 2018 at 16:56 UTC | |
Re: Check multiple lines exist in a record
by choroba (Cardinal) on Mar 26, 2018 at 14:06 UTC | |
by gbwien (Sexton) on Mar 26, 2018 at 14:10 UTC | |
Re: Check multiple lines exist in a record
by karlgoethebier (Abbot) on Mar 27, 2018 at 14:18 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |