#!/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 61dog 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.
How would I go about getting what I need though.if ($var =~ /dog\s(\d+)$/) { print "$TOC{$1}\n";
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 saidif ($_ =~ /(\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)";
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.
Edited 2001-01-02 by Ovid
In reply to Is it Possible to match contents in hash via a Regex? by brassmon_k
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |