|Syntactic Confectionery Delight|
Same pattern match different linesby brassmon_k (Sexton)
|on Aug 20, 2001 at 21:45 UTC||Need Help??|
brassmon_k has asked for the
wisdom of the Perl Monks concerning the following question:
Monks, please bestow upon me your wisdom. I have a pattern match problem. The problem is:
($msisdn) is a phone number
I match a variable ($msisdn) from STDIN. It works in a small text file from which I copied data from a big text file. I have my script reading in paragraphs splitting on the newline and it matches paragraph headings as $lines and then searches for the variable ($msisdn) after it finds the appropriate paragraph heading. There are multiple paragraph headings of the same name throughout the document but with different ($msisdn's). The problem I'm having is the line that ($msisdn) is on isn't the same line throughout the document. The lines aren't being switched it's just that the "mSOriginating" paragraph has less or more lines sometimes, and I've been telling this script to look on different lines for the ($msisdn) but it doesn't seem to want to look on other lines and if it does it ignores the ($msisdn) match or it prints off all of the same paragraph headings in the entire document. I'll post the text I'm going through below. Now in this case the ($msisdn) is on line 43 or $lines and that works fine but for the same paragraph heading "mSOriginating" (which occurs multiple times in my large text file) the ($msisdn) isn't always on line 43. So when my script finds that the ($msisdn) isn't on line 43 it complains that I have an uninitialized value for the pattern match in my pattern match statement. I don't get it:( The pattern match works but then it doesn't:< I'll show the text file first then my script. The line you want to look at in the text is the second from the bottom it's the "Called Party" line.
Now the script:
Now if I do this:
The script doesn't function properly. It will print nothing out except the uninitialized error msgs. Now if I try separate if statements one below another in the same if it still does the same thing, example:
Now according (To my thought pattern atleast) Each if should be evaluated in order if the damn script can't match the ($msisdn) on 43 then it sees the next if for line 30 and if it finds nothing or if it does it shouldn't spit out uninitialized value errors. Even if I tell the script for "mSOriginating" all the lines it will find ($msisdn) 43, 30, etc... it will still error out with the named errors. However if I do this:
It works and gives no errors. That makes no sense at all. If I tell it to find the pattern for line 30 of the "mSOriginating" paragraph it will, and will give no errors. But if I tell it line it will give errors. Even though both lines 43 and 30 (different "mSOriginatg") paragraphs have the ($msisdn) in the right place. I tested it so I know both work. The line 30 if will work in the big and small text file (This is what I need) but line 43 won't. However in the small text file the line 43 match works. In the small file however I only put "mSOriginating" paragraphs in that have the ($msisdn) on line 43 but I know it works because I copied and pasted them out of the big text file. Sorry for the length but I'm deeply troubled by this. My ship is sinking throw me a personal flotation device.
Edit Masem 2001-08-20 - Several code/escape character edits for readability