Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Check multiple lines exist in a record

by jeffenstein (Friar)
on Mar 26, 2018 at 16:56 UTC ( #1211770=note: print w/replies, xml ) Need Help??


in reply to Check multiple lines exist in a record

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 .....

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2020-11-27 12:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?