Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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

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

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

OK That's really neat, I wasn't thinking at it like that. I kind of thought that's what you wanted me to do but wasn't sure, I see now though. However, one final problem, OK, I don't know what any of the lines will be so how do I tell the script that if it matches one of the numbers to print out the correct value from the hash.

You're telling it to print out Miami for $cells{1} but I don't know what the cell site line is going to be it might be 503E so I'd have to tell it somehow to print out the name when you find the number in the record block and in the hash so it knows what key/value to print. So my dilemma is really the printing and matching.

I can do both for a single match no problem. However I have to do 387 of them because there are 387 different Cell site names. So how can I tell the if statement this.

Well your regex will match any cell site line I know that, and if it's under the "if (lastHeading = "MSTerminating)" then it will only evaluate in an "MSTerminating" record block so that one is good and now the final problem which I haven't been able to solve. How do I tell the script to print out the line without knowing what number will be matched. In my current script I don't know why "$_" won't print, but that's the only way I can guess to print out something when you don't know what the answer will be but you know what you want to do with the answer.

The Brassmon_k
  • Comment on Re: Re: Re: Re: Can I match a range from an array?

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Can I match a range from an array?
by rchiav (Deacon) on Aug 03, 2001 at 23:08 UTC
    OK.. you really should look at perlre. The regex /CI: x'(\w+)$/ looks for "CI: x'<one or more word characters><end of line>".
    The parens around the \w+ capture that to the variable "$1". And that is going to be the code you're looking for. So in my example.. $1 == "503E". And for any line, it's going to equal whatever is between "x'" and the end of the line.

    Hope that clairifies things. And also.. read all of perlre. All of this will be much clearer, and you're probably completely rewrite your script as a result of learning what you can do with regular expressions.


      That's it....THAT'S IT!!! WOOOHOOO!
      IT WORKS!

      Praise rchiav for his great knowledge!

      It does exactly as I want it to now.
      With the hash, your "if statement" and some of my code
      it works! It now prints off the lines I tell it to based off the MSISDN\phone number from the appropriate/matching record block title and matches the correct "Cell ID" number\key from the hash and associates the key with it's value and prints the correct name.

      I understood the regex and I understand them and I knew what you wrote. I will look at "perlre". The thing is I can write em but some of the stuff I don't know how it works. For instance you put the $ at the end of your pattern match. I knew what every part of your regex meant except the "$". I think it means match at end of line (not sure though). Then I didn't know that $1 became the variable for the numbers. I thought it was referring to the "key" in the hash so it would print off the first value of the first key in the hash.
      The Brassmon_k

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://102088]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (13)
As of 2017-10-19 13:51 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (253 votes). Check out past polls.