Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

pat match mult/lines mult/pat

by brassmon_k (Sexton)
on Jul 26, 2001 at 23:15 UTC ( #100092=perlquestion: print w/ replies, xml ) Need Help??
brassmon_k has asked for the wisdom of the Perl Monks concerning the following question:

Great Monks,

First off I never ever matched on multiple lines cuz I never had to. That is a prob for me. I have to go through pages of the text below: I'll describe my prob here and you can look through the text and my proposed solution is below the text. OK first off you see the crazy heading mSOriginatingSMSinSMSIWMSC that is the record block title Then the data for the record. The data I need to have matched are the lines I've enclosed with exclamation marks. Here's how
I need them matched.

What this script is concerned about is multiple Title block names. Lines called "Calling or Called Party" that have a MSISDN or phone number which a person running a search would specify by <STDIN>.

What I need done is relatively simple but I've tried working on this for like 3 days and get jack for results. What I need is for this search to:

Search through the text (When it finds the MSISDN number the user entered on <STDIN> the script needs to print the Record Block title, the Called Party & Calling Party lines, the Charged Party line, the Chargeable Duration line, and the Cell ID line. It gets worse because the same lines aren't in all the Record Blocks and I don't have a clue on how to structure this. So I'd have to say something like this to the script.

Okay if you find the MSISDN that I gave you look and find the record block title (Let's just say 3 types although there are more MSTerminating, MSORIGINATING, TRANSIT) if it is MSTerminating print these lines, if it is MSORIGINATING print these lines, If it is TRANSIT print these lines

Here is the text:
!mSOriginatingSMSinSMSIWMSC! Call Identification Number: 10275084 Record Sequence Number: 2205369 Exchange Identity: MAPP01E 0117802 MSC Identification: TON: 1 NPI: 1 MSISDN: 19207079800 !Calling Party Number: TON: 1 NPI: 1 MSISDN: 19207029659! !Date for Start of Charge: 01/07/18! !Time for Start of Charge: 00:14:33! Traffic Activity Code: TeleService Code: x'22 Service Centre Address: TON: 1 NPI: 1 MSISDN: 14147139800 !Charged Party: 0! Miscellaneous Information: NULL !MSTerminating! Call Identification Number: 10275019 Related Call Number: 10275004 Record Sequence Number: 2205370 Exchange Identity: MAPP01E 0117802 MSC Identification: TON: 1 NPI: 1 MSISDN: 19207079800 !Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'4F07! Incoming Route: MAD01TI Outgoing Route: BAPL01O !Calling Party Number: TON: 4 NPI: 1 MSISDN: 6082572086! !Called Party Number: TON: 1 NPI: 1 MSISDN: 16084466501! IMSI: 310640010049547 IMEI: NULL Mobile Station Roaming Number: TON: 1 NPI: 1 MSISDN: 16084469974 Redirecting Number: NULL Redirection Counter: 0 Original Called Number: NULL !Date for Start of Charge: 01/07/18! !Time for Start of Charge: 00:14:33! !Chargeable Duration: 00:00:00! Traffic Activity Code: *020 TeleService Code: x'11 Bearer Service Code: NULL Internal Cause and Loc: LOCATION: 2 CAUSE: 61 Time from Register Seizure to Start of Charging: 00:00:18 Time for Stop of Charging: 00:14:33 Interruption Time: 00:00:00 Type of Calling Subscriber: 1 Disconnecting Party: 2 Charged Party: 1 Fault Code: NULL eosInfo: x'0 Call Position: 2 Miscellaneous Information: NULL Restart During Call: NULL Restart Between Disc and Output: NULL Origin for Charging: x'1 Cell ID for Last Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'4F1D Location Number: TON: 1 NPI: 1 MSISDN: 14147089800 Output for Subscriber: NULL Last Partial Output: NULL Partial Output Rec Num: NULL Regional Service Used: NULL Region Dependent Charging Origin: NULL Transparency Indicator: NULL dTMFUsed: NULL Tariff Class: x'A Tariff Switch Indicator: 0 SS Code: NULL ICI Ordered: NULL
I was thinking if I do something like the below I can get what I want?
print "What msisdn?"; chomp($var = <STDIN>); @patterns = qw($var, $var1, $var2, $var3); $var1 = "MSTerminating" $var2 = "MSORIGINATING" $var3 = "CallForwarding" open(FILE, "output.abbazabba"); while (<FILE>) { foreach $pat (@patterns) { if ( /$pat[1]/ && /$pat[2]/) { print "theselines"; if ( /$pat[1]/ && /$pat[3]/) { print "theselines"; if ( /$pat[1]/ && /$pat[4]/) { } } } } }
However the matching statements don't seem to want to accept the match for 2matches with the (and) operator. I'd assume they would but I don't know how to say if you match this and this then print this with the proper syntax. I'm lost.

Please Help.
The Brassmon_k

Comment on pat match mult/lines mult/pat
Select or Download Code
Re: pat match mult/lines mult/pat
by Zaxo (Archbishop) on Jul 27, 2001 at 01:32 UTC

    You say:

    print "What msisdn?"; chomp($var = <STDIN>); @patterns = qw($var, $var1, $var2, $var3); $var1 = "MSTerminating" $var2 = "MSORIGINATING" $var3 = "CallForwarding"

    qw() does not interpolate, and you do not define $varn before forming @patterns. You should say:

    print "What msisdn?"; chomp($var = <STDIN>); $var1 = "MSTerminating" $var2 = "MSORIGINATING" $var3 = "CallForwarding" @patterns = ($var, $var1, $var2, $var3);

    After Compline,
    Zaxo

    Update: removed color from listings

Re: pat match mult/lines mult/pat
by bikeNomad (Priest) on Jul 27, 2001 at 01:56 UTC
    Beyond the qw() problem that has already been noted, your logic is a bit odd:
    foreach $pat (@patterns) { if ( /$pat[1]/ && /$pat[2]/) { print "theselines"; if ( /$pat[1]/ && /$pat[3]/) { print "theselines"; if ( /$pat[1]/ && /$pat[4]/) {

    First, you're ignoring $pat[0] altogether. Then, you're using a non-existent element $pat[4]. And you're manually unrolling a loop and putting it inside a loop. If all you want to do is print a line when it matches what came from stdin and matches one of several patterns, just do something like this:

    chomp(my $var = <STDIN>); $var = qr($var); my $pattern = qr($var1|$var2|$var3); while (<FILE>) { print if /$var/ && /$pattern/; }
      Yes I realized the mistakes I put in my initial entry like not defining the scalars above the array and neglecting array0 and array4 was non-existant.

      I've already achieved the results that your idea puts out. I guess my problem is a bit odd to explain.
      Those results are:
      Calling Party Number: TON: 4 NPI: 1 MSISDN: 6082572086 Calling Party Number: TON: 4 NPI: 1 MSISDN: 6082572086 Charge Number: TON: 3 NPI: 1 MSISDN: 6082572086 Calling Party Number: TON: 4 NPI: 1 MSISDN: 6082572086 Calling Party Number: TON: 4 NPI: 1 MSISDN: 6082572086 Called Party Number: TON: 2 NPI: 1 MSISDN: 16082572086 Called Party Number: TON: 2 NPI: 1 MSISDN: 16082572086
      Here's what I did with your idea.
      chomp(my $var = <STDIN>); $var = qr($var); $var1 = "MSTerminating" $var2 = "MSORIGINATING" $var3 = "TRANSIT" my $pattern = qr($var1|$var2|$var3); while (<FILE>) { print if /$var/ && /$pattern/; }
      Now you see what this bit of code did seemingly match only the $var it's like (and) operator pattern matches are ignored and only one is accepted.

      However I did indeed want those lines printed off but I also wanted the record block titles to print. If I do "print if /$vara/" it will do what I want print the record block titles but it will print all of them in the entire document. I only want it to print the section title when it finds the phone number. What I desire is output like the following: So to say it as clearly as I can is if I find the phone number in a record block such as "MSTerminating" or "MSORIGINATING" print the lines I specify like,
      line1
      line2 etc.
      Is there anyway to tell PERL that "MSTerminating" is line1 for a record block and this "Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'4F07" would be line13? Can you tell perl line numbers because I've been looking and that would be ideal for my situation then it would be easy as pie. I could arrange something such as - if you find $var in "MSTerminating" print $line1, $line2, etc. Then the exact results would be there. The only problem is each record block (Like 8 different ones) have a different number of lines and different data in each type of record block. The desired example output is below and I've illustrated the differences with putting (line#) after the text for 3 of the entries as you can see.
      MSTerminating Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'4F07 Calling Party Number: TON: 4 NPI: 1 MSISDN: 6082572086 (line15) Called Party Number: TON: 1 NPI: 1 MSISDN: 16084466501 (line16) Date for Start of Charge: 01/07/18 (line18) Time for Start of Charge: 00:14:33 Chargeable Duration: 00:00:00 MSORIGINATING Calling Party Number: TON: 4 NPI: 1 MSISDN: 6082572086 (line10) Called Party Number: TON: 1 NPI: 1 MSISDN: 16084466501 (line11) Date for Start of Charge: 01/07/18 (line30)
      Please for the love of lines how do you do accomplish telling PERL this. I've scoured the net and a few books I have to try to figure out how to tell PERL which line to print but all I've found is pattern matching because it's easier. Well unfortuneately I think I need to know how to tell PERL go print line1 then line13 if you find this number under the "MSTerminating" block because that's the only way it can be done in my case I think.

      The Brassmon_k
      David M. Hagens
      Airadigm Communications
Re: pat match mult/lines mult/pat
by bikeNomad (Priest) on Jul 27, 2001 at 20:40 UTC
    I hope that isn't live data. Does your employer want everyone to know that the person at 6082572086 called 16084466501 and talked for 14 minutes?
      No it's made up data -
      So any ideas

      Dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (14)
As of 2014-10-30 12:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (207 votes), past polls