You could read each record into an array, and check it as a unit:
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw(say);
use List::Util qw(first);
my $rec_no = 0;
my @record;
my $msisdn;
while(<>){
chomp;
if(/^<SUBBEGIN/){
@record = ($_);
$msisdn = undef;
say "Found record: ", ++$rec_no;
next;
}elsif(/^<SUBEND/){
push @record, $_;
check_record(\@record);
@record = ();
}elsif(/^\s*MSISDN=(\d+);/){
$msisdn = $1;
say "Record $rec_no: MSISDN = $msisdn";
}else{
push @record, $_;
}
}
exit 0;
sub check_record {
my $listref = shift;
if( first {/^\s*CF=(CFU-TS10-ACT-(NONE|\d+))/} @{$listref}
and first {/^\s*CF=(CFB-TS10-ACT-(NONE|\d+))/} @{$listref}
){
say "this case is found here .....";
}
}
It's a bit of a brute-force solution, but it should work.
Sample output:
$ ./t.pl
Found record: 1
Record 1: MSISDN = 1234567890
this case is found here .....
Found record: 2
Record 2: MSISDN = 1234567890
this case is found here .....
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|