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