Hi,

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;

In reply to Check multiple lines exist in a record 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.