Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: Re: Can I match a range from an array?

by brassmon_k (Sexton)
on Aug 03, 2001 at 19:25 UTC ( #102007=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Can I match a range from an array?
in thread Can I match a range from an array?

OK that is so cool that you helped me. I finally got it but yet I don't. My brain block went away and I figured it out. Haven't gotten to much sleep lately. Here it is an almost working version that does everything I want. Now what I can't figure out is the fact that for the if statement you know if ( $cellsite{cell} ) and if ( $cellsite{cell1} ) it's A: obviously finding the Cell ID lines because it prints them out but the problem is B: The "if" statements are supposed to match up with the right "Cell ID" line and only print out the value for that key. My problem is that when I put in the phone number to limit the search results and the value for the key is the "Cell ID MAD023" one it still will print the "Cell ID APPL03". See their are 2 "MSTerminating" record blocks in the file it searches through each have 2 different numbers and 2 different "Cell ID lines" the problem is though that it prints both values for one phone number. What am I doing wrong. The output of the script I'll place below the script. I'm not that familiar with voting here cuz I just hit level 2 today and that (++) or (-) radio buttons above our entries (Didn't see that on level one) but I can give you guys like
++ points right? If that's the case you guys are getting em. I'm just double checking with you guys. Anyway here's the code.

#!/usr/bin/perl -w use strict; my $msisdn; my $cell; my %cellsite; my $lastHeading; my $para; my @lines; my $cell1; chomp($msisdn = <STDIN>); $cell = "Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x' +4F07"; $cell1 = "Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x +'APP03"; %cellsite = ("$cell", "Cell ID for First Cell: MCC: 310 MNC: 64 LAC: + x'44D CI: x'MAD023", "$cell1", "Cell ID for First Cell: MCC: 310 M +NC: 64 LAC: x'44D CI: x'APP03"); $/ = ""; # read paragraphs while ($para = <>) { @lines = split(/\n/, $para); if (@lines == 1) # A Heading { $lastHeading = $lines[0]; next; } if ($lastHeading eq "MSTerminating") { if ($lines[8] =~ m/$msisdn/) { if ( $cellsite{$cell} ) { print "$cellsite{$cell}\n"; } if ( $cellsite{$cell1} ) { print "$cellsite{$cell1}\n"; } print "MSTerminating\n"; print "\n"; print "$lines[8]\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"; } } }
Command line/Script output.
$ exp4.53 output #Command line 6082572086 #Command line OUTPUT Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'MAD023 Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'APP03 MSTerminating Calling Party Number: TON: NPI: 1 MSISDN: "phone number" MSC Identification: TON: 1 NPI: 1 MSISDN: "phone number"
So you can see my problem. For the phone number I looked up in this record block the "Cell ID" line has "4F07" at the end - So the script looks at the hash and prints out the appropriate garbage. However for the "Cell ID" line "503E" isn't there and that when translated to it's name is "APP03" so that shouldn't have printed but it did anyway even though that number isn't in the "Cell ID" line for this particular record block. So it's printing one line of garbage. What's the problem, I can't figure this out.

The Brassmon_k


Comment on Re: Re: Re: Can I match a range from an array?
Select or Download Code
Re: Re: Re: Re: Can I match a range from an array?
by snafu (Chaplain) on Aug 04, 2001 at 00:14 UTC
    Would it be possible for you to give mock lists with saaaay, three records, the tranlation list your boss gave you (that have corresponding data in it that match up to the cdr's) and anything else that would make testing in a duplicate environment easier?

    ----------
    - Jim

      Well I won't have to do that now. The only problem I had left was an incorrectly formed regex. I knew a regex was my answer but I wasn't putting in the right one. I also knew I had to use a hash. I never really had to use them before because I never had to get a 387 different line match to work before with a hash. Hashes are beautiful, it knew what to print out. Well it's been fixed now so it's cool.

      Well if you still want to take a look let me know.

      The Brassmon_k

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2014-11-28 01:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (191 votes), past polls