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


In reply to Re: Re: Re: Can I match a range from an array? by snafu
in thread Can I match a range from an array? by brassmon_k

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.