Monks I seek your supgreme knowledge,
Okay this script (It's in development as of yet that's why it so nappy looking right now)
What the script (immediately below this paragraph) does is go through a bunch of cellular call records (Immediately below the script) The script does pattern matches on a phone number and in a record block (Record Blocks are separated by Newlines) and prints out the lines I specify. Each record block has different data and a different amount of lines.
When I'm finished I'll use strict and warnings and indent my code but now it's in the rough so it doesn't matter.
#!/usr/bin/perl
chomp($msisdn = <STDIN>);
$/ = ""; # read paragraphs
while ($para = <>) {
$lastHeading;
@lines = split(/\n/, $para);
if (@lines == 1) # A Heading
{
$lastHeading = $lines[0];
next;
}
if ($lastHeading eq "MSTerminating") {
if ($lines[8] =~ m/$msisdn/) {
print "MSTerminating\n";
print "\n";
print "$lines[9]\n";
print "$lines[4]\n";
}
}
elsif ($lastHeading eq "MSORIGINATING") {
if ($lines[7] =~ m/$msisdn/) {
print "MSORIGINATING\n";
print "\n";
print "$lines[7]\n"; # sixth line
}
}
elsif ($lastHeading eq "TRANSIT") {
if ($lines[7] =~ m/$msisdn/) {
print "$lines[7]\n";
}
}
elsif ($lastHeading eq "mSOriginatingSMSinSMSIWMSC") {
if ($lines[4] =~ m/$msisdn/) {
print "$lines[4]\n";
}
}
}
Here is the TEXT
I only showed one record block as they are quite lengthy.
MSTerminating
Call Identification Number: 10275050
Related Call Number: 10275036
Record Sequence Number: 2205392
Exchange Identity: MAPP01E 0117802
MSC Identification: TON: 1 NPI: 1 MSISDN: "PHONE NUMBER"
Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'503E
Incoming Route: AORX02I
Outgoing Route: BAPL01O
Calling Party Number: TON: 4 NPI: 1 MSISDN: "PHONE NUMBER"
Called Party Number: TON: 1 NPI: 1 MSISDN: "PHONE NUMBER I LOOK FOR IN
+ AN MSTERMINATING RECORD BLOCK"
IMSI: 310640010070933
IMEI: NULL
Mobile Station Roaming Number: TON: 1 NPI: 1 MSISDN: 19207079858
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:38
Chargeable Duration: 00:00:00
Traffic Activity Code: *020
TeleService Code: x'11
Bearer Service Code: NULL
Internal Cause and Loc: LOCATION: 11 CAUSE: 46
Time from Register Seizure to Start of Charging: 00:00:15
Time for Stop of Charging: 00:14:38
Interruption Time: 00:00:00
Type of Calling Subscriber: 0
Disconnecting Party: 0
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'503E
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
What my problem is: In each Record Block as you'll see in the text of the call record I displayed below (None of the data is live data) is 2 lines which say(One towards the top and the other towards the bottom):
Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'something'
Cell ID for Last Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'something'
As you can see the entire line is the same except for the last portion that is my problem.
I was given a list with 387 names of cell sites that correspond to the CI: x'something' portion where something is a number which translates to a name on the list I was given. Now the problem is if I want to get the results I have to do this:
$cell = "Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'272
+6'";
if (m/$cell/) {
print Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'APPL20
+';
or I could just do a pat match with the if statement using the string instead of using a scalar
The issue is that I would have to do an "if" and a "print" statement for each of the lines I wish to match so the correct name can be printed out for the appropriate record block and phone number.
That would be (744) lines of code just for the "Cell ID for First" and an additional (744) lines for "Cell ID for Last" a total of (1548) lines of code per record block and I will be searching through 4 or more record blocks which is a total of (6192) lines of code.
Needless to say I don't even want to think about that. I want to shorten this (Not to mention this way is inefficient).
Here's how I'm pattern matching:
$1 = "Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'271B'"
+;
%Firstcell = (
Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'2726',
Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'271B',
Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'3001');
@First = %Firstcell;
($a, $b, $c) = @First;
if (lines[05] == m/$b/) {
print "$1";
}
See I can get it to match but here's the problem. I have 387 of those lines so I'd have to do:
if (lines
05 == m/$b/ || m/$c/ || m/until 387/) {or course in order} Isn't there something where I can say:
if (lines
05 == m/$a/ - m/$z/) So I can see if there is a match for the entire group instead of doing the logical OR for each scalar which correlates to a pattern?
One thing I don't think I can get around (Pretty sure) is writing out the $1 = "print this" because each is specific and the PERL can't guess the right answer. I have to tell it what it is.
So my only problem summed up is:
If I put all 387 lines in the %Firstcell hash then make @First = %Firstcell and finally $a, $b, etc until I have all 387 scalars in the @First, is there a way I can run all 387 lines through a pattern match (like a range) all at once instead of typing "||" for each separate match?
The Brassmon_k,
May the Schwartz be with you.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.