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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Monks,

Ran into a road block while writing some code and I can't figure out how to figure it out. The problem: I have essentially DB oriented code and it has a built-in menu and goes through the text and reports the results back to the searcher. However this text is just a bunch of numbers (23 fields all separated by a single space and fields can range from 2 to 16 digits in length) Now for field 15 I set up a hash with the values of the numbers that reflects regular understandle text so field 15 will have meaning to the searcher instead of just being numbers. However I can't figure out how to get the damn line to print with the Decoded value in the line. Here is the script:
#!/usr/bin/perl -w use strict; my $datemin; my $datemax; my $timemin; my $timemax; my $choice; my $msisdn; my $range; my $rangex; my %TOC; %TOC = ( 'DID' => "Digit Feed Recieved", 'ETE' => "No digit feed/calle +r enters mailbox number", 'ODL' => "Outidal Delivery", 'ODN' => "Outdial Notification", 'DEP' => "Deposit Only", 'RET' => "Re +trieval Only", 'SMD' => "SMDI serially integrated trunk", 'PAG' => "Page delivery", 'ISI' => "Infoserv Recording", 'TAS' => "TAS + Call", 'TTT' => "Trunk to trunk transfer", 'PBX' => "PBX type transfer", 'CMC' => "Constant Touch", 'CMO' => "Con +stant Touch Outdial notification" ); print "Your Options Are:\n"; print "\n"; print "DateSearch Only = 'd'\n"; print "TimeSearch Only = 't'\n"; print "Msisdn Search Only = 'm'\n"; print "Date & Time Search = 'b'\n"; print "\n"; do { print "Select Your Option:> (d, t, m, b)"; chomp($choice = <STDIN>); } until ($choice =~ /^[DdTtMmBb]/); if ($choice =~ /^[Dd]/) { $range = <STDIN>; ($datemin, $datemax) = split /-/, $range; # Squeeze out leading and trailing spaces $datemin =~ s/^\s+//; $datemin =~ s/\s+$//; $datemax =~ s/^\s+//; $datemax =~ s/\s+$//; print "beg: $datemin end: $datemax\n"; print "Matches\n-------\n"; open(FILE, "/dave/MVPTEST/mvpdoc"); while (<FILE>) { chomp; if ($_ =~ /(\d{4})\s(\d{5})\s(\d{3})\s(\d{2})\s(\d{2}\ +/\d{2}\/\d{2})\s(\d{2}\:\d{2}\:\d{2})\s(\d{3})\s(\d{2})\s(\S+)\s(\d{2 +})\s(\d{2})\s(\d{2})\s(\d{2})\s(\w{3})$/) { if (($5 ge $datemin) && ($5 le $datemax)) { print "$_\n"; } } } } if ($choice =~ /^[Tt]/) { $rangex = <STDIN>; ($timemin, $timemax) = split /-/, $rangex; # Squeeze out leading and trailing spaces $timemin =~ s/^\s+//; $timemin =~ s/\s+$//; $timemax =~ s/^\s+//; $timemax =~ s/\s+$//; print "beg: $timemin end: $timemax\n"; print "Matches\n-------\n"; open(FILE, "/dave/MVPTEST/mvpdoc"); while (<FILE>) { chomp; if ($_ =~ /(\d{4})\s(\d{5})\s(\d{3})\s(\d{2})\s(\d{2}\ +/\d{2}\/\d{2})\s(\d{2}\:\d{2}\:\d{2})/) { if (($6 ge $timemin) && ($6 le $timemax)) { print "$_\n"; } } } } elsif ($choice =~ /^[Mm]/) { chomp($msisdn = <STDIN>); print "Matches\n-------\n"; open(FILE, "/dave/MVPTEST/mvpdoc"); while (<FILE>) { chomp; if ($_ =~ /(\d{4})\s(\d{5})\s(\d{3})\s(\d{2})\s(\d{2}\/\d{ +2}\/\d{2})\s(\d{2}\:\d{2}\:\d{2})\s(\d{2})\s(\S+)/) { if ($8 =~ $msisdn) { print "$_\n"; } } } } elsif ($choice =~ /^[Bb]/) { $range = <STDIN>; $rangex = <STDIN>; # Break up the range ($datemin, $datemax) = split /-/, $range; ($timemin, $timemax) = split /-/, $rangex; # Squeeze out leading and trailing spaces $datemin =~ s/^\s+//; $datemin =~ s/\s+$//; $timemin =~ s/^\s+//; $timemin =~ s/\s+$//; $datemax =~ s/^\s+//; $datemax =~ s/\s+$//; $timemax =~ s/^\s+//; $timemax =~ s/\s+$//; print "beg: $datemin end: $datemax\n"; print "beg: $timemin end: $timemax\n"; print "Matches\n-------\n"; open(FILE, "/dave/MVPTEST/mvpdoc"); while (<FILE>) { chomp; if ($_ =~ /(\d{4})\s(\d{5})\s(\d{3})\s(\d{2})\s(\d{2}\/\d{ +2}\/\d{2})\s(\d{2}\:\d{2}\:\d{2})/) { if (($5 ge $datemin) && ($5 le $datemax) && ($6 ge $ti +memin) && ($6 le $timemax)) { print "$_\n"; } } } }

First yeah I know it was long and second I don't know how good my indenting is for the code. Usually I just post it in block form. Anyway you saw the hash in the very beginning called %TOC and the values of field 15 are defined. Well Duh you guys know that. Anywho here is an example of the data I'm going through.

4478 00300 064 01 01/11/19 00:00:46 03 00000092a71228a9 255 01 00:00:3 +0 01 00 00 00 DID 0000000000000000 000 0000000000000000 0000000000000 +000 0000000000000000 000 61

Now as it stands the script prints the line off as is above but I want to integrate the value of %TOC into the printed off line. The value for this line for field 15 being DID is "Digit Feed Recieved" I want that printed off in the line like the example below.

4478 00300 064 01 01/11/19 00:00:46 03 00000092a71228a9 255 01 00:00:30 01 00 00 00 (Digit Feed Recieved) 0000000000000000 000 0000000000000000 0000000000000000 0000000000000000 000 61
I can do single lines like something that was like this
dog 001 cat 002

Yeah I can match and print single lines but I never had to print off something that was internal to a line. I can do the following to get hash values printed.

if ($var =~ /dog\s(\d+)$/) { print "$TOC{$1}\n";
How would I go about getting what I need though.
if ($_ =~ /(\d{4})\s(\d{5})\s(\d{3})\s(\d{2})\s(\d{2}\/\d{2}\/\d{2})\s +(\d{2}\:\d{2}\:\d{2})\s(\d{3})\s(\d{2})\s(\S+)\s(\d{2})\s(\d{2})\s(\d +{2})\s(\d{2})\s(\w{3})$/) { print "$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $TOC{$15)";
I think the above would work but I can't test it because for some reason (Which I don't know) The script will read fields like $5 for a match but it won't print them. So if I said
print "$1, $2";

The script won't do it. It will only print off my results using "print $_"; and I've used the $field vars before to get stuff to print but I don't get why this stuff won't.


I kinda know how to do it but I more or less confused myself between a rock and a confused spot. Please help me clear the fog up a little,

All help will be sincerely appreciated. Like I said though I think my indenting sucks.

The Brassmon_k

Edited 2001-01-02 by Ovid


In reply to Is it Possible to match contents in hash via a Regex? 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 about the Monastery: (2)
As of 2024-04-25 20:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found