Perl-Sensitive Sunglasses | |
PerlMonks |
Can I match a range from an array?by brassmon_k (Sexton) |
on Aug 03, 2001 at 01:40 UTC ( [id://101797]=perlquestion: print w/replies, xml ) | Need Help?? |
brassmon_k has asked for the wisdom of the Perl Monks concerning the following question:
Monks I seek your supgreme knowledge, Okay this script (It's in development as of yet that's why it so nappy looking right now) What the script (immediately below this paragraph) does is go through a bunch of cellular call records (Immediately below the script) The script does pattern matches on a phone number and in a record block (Record Blocks are separated by Newlines) and prints out the lines I specify. Each record block has different data and a different amount of lines. When I'm finished I'll use strict and warnings and indent my code but now it's in the rough so it doesn't matter. Here is the TEXT I only showed one record block as they are quite lengthy. What my problem is: In each Record Block as you'll see in the text of the call record I displayed below (None of the data is live data) is 2 lines which say(One towards the top and the other towards the bottom): Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'something' Cell ID for Last Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'something' As you can see the entire line is the same except for the last portion that is my problem. I was given a list with 387 names of cell sites that correspond to the CI: x'something' portion where something is a number which translates to a name on the list I was given. Now the problem is if I want to get the results I have to do this: or I could just do a pat match with the if statement using the string instead of using a scalar The issue is that I would have to do an "if" and a "print" statement for each of the lines I wish to match so the correct name can be printed out for the appropriate record block and phone number. That would be (744) lines of code just for the "Cell ID for First" and an additional (744) lines for "Cell ID for Last" a total of (1548) lines of code per record block and I will be searching through 4 or more record blocks which is a total of (6192) lines of code. Needless to say I don't even want to think about that. I want to shorten this (Not to mention this way is inefficient). Here's how I'm pattern matching: See I can get it to match but here's the problem. I have 387 of those lines so I'd have to do: if (lines05 == m/$b/ || m/$c/ || m/until 387/) {or course in order} Isn't there something where I can say: if (lines05 == m/$a/ - m/$z/) So I can see if there is a match for the entire group instead of doing the logical OR for each scalar which correlates to a pattern? One thing I don't think I can get around (Pretty sure) is writing out the $1 = "print this" because each is specific and the PERL can't guess the right answer. I have to tell it what it is. So my only problem summed up is: If I put all 387 lines in the %Firstcell hash then make @First = %Firstcell and finally $a, $b, etc until I have all 387 scalars in the @First, is there a way I can run all 387 lines through a pattern match (like a range) all at once instead of typing "||" for each separate match? The Brassmon_k, May the Schwartz be with you.
Back to
Seekers of Perl Wisdom
|
|