Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Well that's not quite what I was referring to.

Here's what I understand:
-You have a line that has a number at the end of it that signifies something.
-You want to print something depending on the number.
-I'm assuming that what you want to print is the name of the cell site.

Soooo.. What I would do is the following..

#!/usr/bin/perl -w use strict; #putting the line in question into $_ for this example. $_ = "Cell ID for Last Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'503E +"; #create our hash of 'site codes' => 'text to print' my %cells = ('207B' => 'Miami', '432F' => 'Buffalo', '443R' => 'Whatever you want for cell site 443R', '503E' => 'Portland, OR' ); if (/CI: x'(\w+)$/) { print "Cell site is $cells{$1}.\n"; }
Now.. if the regex confuses you, I'd suggest spending a little time with perlre. What this basically does it grabs the last part of the string that you said is variable. Then it takes that and looks it up in the hash. Now this is a very simple example, without error checking and the other various things that you should have in there. You need to take into account if there's no entry in the hash... and how you deal with that.

Hope this helps..
Rich


In reply to Re: Re: Re: Can I match a range from an array? by rchiav
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-23 06:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found