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

Ok. This writeup has particlarly interested me. However, there are a few things that are really 'fusing me.

Is it me or is this snippet of code broken? I don't see how you can get an accurate answer from if (@lines == 1) {....

@lines = split(/\n/, $para); if (@lines == 1) # A Heading { $lastHeading = $lines[0]; next; }

The if-then would always return false and therefore $lastHeading would never get substituted, right? What am I missing?

Next, I am still not positive what the author wants which is probably just my interpretation of the question. Brassmon_k don't take anything I write here personal. I am just asking for my own clarification. I want to help because I find this topic near and dear to my work =P. I work for a telco and deal with this kind of stuff alllll the time. Never done wireless though.
I see that you want call information but I think I am missing how you want to extract this information and what you're grabbing this information from. I have a snippet of code I wanted to present but it works more along the lines of sucking a file (record file) in and spitting out all the lines containing the information I believe you want (not done yet, just grabs all lines with Cell right now). It places every line occurrence into an array and then every 2 lines into another array to seperate first and last cell. BUT, it seems this is not what you want in terms of your desired output, so I am a little lost on the question I think. Thank goodness the other monks could get ya. :) I am finding your question to be jumpy and for me it is not entirely understandable. I should clarify that I KNOW you want to actually get the information extracted from the lines containing 'Cell' in them and if I can get further personal clarification on this I can then tweak what I have so far and present it if you'd like.

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

Replies are listed 'Best First'.
Re: Re: Can I match a range from an array?
by Zed_Lopez (Chaplain) on Aug 03, 2001 at 22:08 UTC
    @lines is being evaluated in a scalar context here and thus returning the number of elements in @lines. For a $para with only one line, it'll be true.
      Ahh yes. Ok. I thought this but I didn't think you could do that without explicitly expressing that the array was being compared as a scalar. I researched it a lil bit more and found out that what I have is failing not because of the if statement but because he is creating the array @lines from his data which will definitely be greater than 1 and this is why it seems to be failing for me. Again, I must be missing something else here. Maybe I just didn't duplicate the situation correctly on my side. If I debug it here is what I get:

      [jconner@kwan ~]$ cat celldata | perl -d code.pl Default die handler restored. Loading DB routines from perl5db.pl version 1.07 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(code.pl:4): chomp(my $msisdn = <STDIN>); DB<1> t Trace = on DB<1> s main::(code.pl:5): $/ = ""; # read paragraphs DB<1> main::(code.pl:6): my $para; DB<1> main::(code.pl:7): my $lastHeading; DB<1> main::(code.pl:9): while ($para = <>) { DB<1> main::(code.pl:11): my @lines = split(/\n/, $para);

      So, here we see that we sucked in the file which is the data he presented in the post.

      DB<1> print $para main::((eval 26)[/usr/local/lib/perl5/5.6.0/perl5db.pl:1510]:2): 2: print $para; 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

      Ok, so now the next thing that will happen is that he splits this information up into an array called @lines.

      DB<2> main::(code.pl:13): if (@lines == 1) { # A heading DB<2> print scalar @lines main::((eval 27)[/usr/local/lib/perl5/5.6.0/perl5db.pl:1510]:2): 2: print scalar @lines; 49

      Which now has 48 elements (49-1) I believe...still that is greater than 1.

      DB<3> main::(code.pl:18): if ($lastHeading eq "MSTerminating") { DB<3> Use of uninitialized value in string eq at code.pl line 18, <> chunk 1 +. Use of uninitialized value in string eq at code.pl line 18, <> chunk 1 +. Use of uninitialized value in string eq at code.pl line 18, <> chunk 1 +. Use of uninitialized value in string eq at code.pl line 18, <> chunk 1 +. main::(code.pl:9): while ($para = <>) { DB<3>

      Which of course fails everytime. Where did I duplicate the situation incorrecty?

      Debugged program terminated. Use q to quit or R to restart, use O inhibit_exit to avoid stopping after program termination, h q, h R or h O to get additional info. DB<3>

      I used the following code (derived from his with my minor tweaks, ie strict and warnings enabled and indentation added:

      #!/usr/bin/perl -w use strict; chomp(my $msisdn = <STDIN>); $/ = ""; # read paragraphs my $para; my $lastHeading; my @lines; while ($para = <>) { @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"; } } }
      Thanks guys.

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

Re: Re: Can I match a range from an array?
by brassmon_k (Sexton) on Aug 03, 2001 at 23:13 UTC
    Finally, Some telcom intelligence that might have a better grasp on what I'm trying to do.

    OK what I need to do. Boss gave me a list of cell site locations. They're coded to the BASE10. Now I also have a call record that contains the lines "Cell Site Blah Blah"

    Now I have to limit the info returned when I do a search. I search first by record block, MSTerminating, MSORIGINATING, etc.. Then we narrow it down some more saying OK now only if we see the correct number in the appropriate record block. I don't specify a record block just the MSISDN because really in this entire script that is the anchor. Everything else revolves around finding that. The script works. It prints out what lines I tell it under the right record heading for the number that I specify.

    The problematic portion is what I have to do next. OK as I said my bosses list that he gave me has these types of entries in it:

    GRN001A 310-640-1101-10011
    Now if I type "10011" into a BASE converter going from BASE 10 to BASE 16 the number that is popped out is "271B" which is also at the end of some of the "Cell site" lines in the call record file. With the numbers I know what cell site "271B" to call "GRN001A" because "10011" = "271B" which I will find in the call record on line5 for a "MSTerminating" record block see the "271B" or whole line and have it reprint out as - Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'GRN001A - This abbreviation helps us because now we know that the site is in Greenville prior with the 271B we didn't know where it was.

    All this has been accomplished B4 except that I have 387 of these locations to give the script. It's easy to specify one "if you match it then print it" Problem is "If you match any of these cell sites print the right one" That's my problem, I can't tell the script "If you find any of these" or "If you find it print out the correct one"

    Now that I've described my process, you said you're using a call record also. Call Records are fairly standard I know your from a land base so yours are probably different but they are both call records so it should run along the same lines. So maybe that can help me. So post your code if you don't mind. The snippet of code you posted is correct what it does is this:

    Split @lines by new line (So it's reading in paragraphs) Next line @lines == 1
    Thats saying if it's true then $lastHeading = line0 or the first elmement of the array which are the record titles such as "MSTerminating, MSORIGINATING. Then a next; to go on to the rest of the code. It works. Oh I don't know if this would be of interest to you but I have a script that takes call records and can sort through them by date and time (file form is this) TTFILE03.3483010712234522 = .(4random numbers)(6digit date YYMMDD)(6digit time HHMMSS) the script returns the matching call records then searches them for a phone number and spits out the lines I want. I have a built shell menu for it. It's the same thing I'm doing here (Well this is just part of it) I'm modifying the muscle portion of the script, the part that rips out all of the lines I want based off the phone number. Modifying because the original is in AWK and I hate AWK and 2 because I have to do this cellsite translation garbage. It's a fun challenge but I need to grab a smoke. I hope I explained the code snippet good enough. My deficit for writing nodes is my sparatic type of writing. That's what happens with 2 cappacuinos (ENGLISH TOFFEE!)

    The Brassmon_k
      hahahaha...ok. Well, I don't do coffee so maybe my calmness and your coffeeness will bring us up to speed =P. First, yup, you're right. I come from the landline side. Actually, our cdr's are really different from what you've shown me. But that is neither here or there. Lets see if I am grasping your needs.

      You have 3 lists then (files). 1 is a list of cell sites in english. Another is a list of cell sites in base10. And finally you have the CDR.

      The file your boss gave you comes with the "cryptic" information that looks like a location id (GRN001A) with the NPA-NXX and suffix (310-640-1101) and then the base10 of identifier of the cell site (10011). The hex conversion of 10011 is 271B which will now match up with the call record (where MSTerminating shows the record block). Now, you want to convert the instance of

      Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'271B
      to...
      Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'GRN001A

      And you want to be able to do this in a massive conversion...
      Do I have the idea? :) As for my code, it wasn't going in the right direction. I will still post it if ya want...its nothing big. I would like to check out the script you are talking about that does the sorting on cdr's. That might help me in something I might undertake soon. Let me munch on this one you have brought up....permitted I understand now what you need and time permitting. I am at work right now which of course takes precedence.

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