brassmon_k has asked for the wisdom of the Perl Monks concerning the following question:
Now the script:PCSPLMNCallDataRecord mSOriginating callPosition + 3'D chargeableDuration 0 1 1'BCD dateForStartOfCharge 1 8 13'BCD exchangeIdentity "MAPP01E 0117802"'S interruptionTime 0 0 0'BCD recordSequenceNumber 15701541'D tariffClass 10'D tariffSwitchInd 0'D timeForStartOfCharge 9 32 31'BCD timeForStopOfCharge 9 33 32'BCD callIdentificationNumber 5025228'D chargedParty 0'D switchIdentity 0001'H subscriptionType 00'H timeFromRegisterSeizureToStartOfCharging 0 0 9'BCD disconnectingParty 1'D internalCauseAndLoc 0 3'BCD mSCIdentification 1119207079800F'TBCD locationNumberOriginating 114141079808F0'H teleServiceCode 11'H iMSICalling 13600410003154F0'H timeForTCSeizureCalling 092015'H cellIDForFirstCellCalling 130046044D55B5'H radioChannelProperty 01'H firstRadioChannelUsed 00'H firstAssignedSpeechCoderVersion 01'H speechCoderPreferenceList 0100'H cellIDForLastCellCalling 130046044D55C8'H ->1|0|125 00'H ->1|0|123 00'H translatedNumber 116180446697F9'H originatingLineInformation 62'D chargeNumber 136084465140'TBCD networkCallReference 244F4A0001'H eosInfo 00'H typeOfCallingSubscriber 1'D originForCharging 1'D trafficActivityCode 11 2 13'BCD outgoingRoute "0GRI2"'S incomingRoute "BAPL01I"'S callingPartyNumber 14xxxxxxxxxx'TBCD ((((Th +is is the $msisdn line)))) calledPartyNumber 1xxxxxxxxF'TBCD
Now if I do this:#!/usr/bin/perl -w use strict; my @lines; my $para; my $lastHeading; my $msisdn; print "What msisdn?"; chomp($msisdn = <STDIN>); $/ = ""; # read paragraphs while ($para = <>) { @lines = split(/\n/, $para); if (@lines == 1) # A Heading { $lastHeading = $lines[0]; next; } if ($lines[1] =~ "mSOriginating") { if ($lines[43] =~ "$msisdn") { print "MSORIGINATING\n"; print "$lines[0]\n"; print "$lines[8]\n"; print "$lines[7]\n"; print "$lines[43]\n"; print "\n"; } } }
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:if ($lines[43] || $lines[30] || etc... =~ "$msisdn")
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:if ($lines[1] =~ "mSOriginating") { if ($lines[43] =~ "mSOriginating") { print "blah"; } if ($lines[30] =~ "mSOriginating") { print "blah"; } }
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[43] 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.if ($lines[30] =~ "$msisdn") {
Edit Masem 2001-08-20 - Several code/escape character edits for readability
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Same pattern match different lines
by brassmon_k (Sexton) on Aug 20, 2001 at 22:36 UTC | |
|
Re: Same pattern match different lines
by Cine (Friar) on Aug 20, 2001 at 22:27 UTC |