Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: Is it Possible to match contents in hash via a Regex?

by brassmon_k (Sexton)
on Jan 07, 2002 at 23:13 UTC ( #136897=note: print w/ replies, xml ) Need Help??


in reply to Re: Is it Possible to match contents in hash via a Regex?
in thread Is it Possible to match contents in hash via a Regex?

Okay everyone here is the finished code sorry it took so long had to test it on 2 other systems besides mine and some slight alterations were needed and the script had to be dressed up a little. I could make it even fancier (That's fun to do once you have the darn thing working!) but the users can have fun with it anyway.

#!/usr/bin/perl -w #SMDR Record Script use strict; my $datemin; my $datemax; my $timemin; my $timemax; my $choice; my $msisdn; my $range; my $rangex; my $SIG; my %TOC; my %DC; my %PAC; %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" ); %DC = ( '00' => "Timeout waiting for command", '01' => "Hang up or log + off", '02' => "DTMF 're-id' entered", '03' => "DTMF 'operator revert' entered", '04' => "DTMF 'call transfer +' entered", '05' => "Successful Outdial", '06' => "No Answer/busy outdial", '07' => "Not Implemented", '08' => " +Hardware or System problem", '09' => "Call terminated by system manager", '10' => "Too many subscri +ber errors", '11' => "Unidentified caller sent urgent message", '12' => "Outdial page fails", '13' => "Outdial page success", '14' => +"Leave system from trunk to trunk transfer", '15' => "Not Implemented", '16' => "Fax Transmission Fails", '17' => " +Subscriber sent Constant Touch caller to voice mail" ); %PAC = ( '00' => "Answer and play greeting", '01' => "Entered mailbox +number and left message", '02' => "Entered user name and left message +", '03' => "Entered mailbox number/password for access", '04' => "Not Imp +lemented", '05' => "Not Implemented", '06' => "Outdial to deliver message", '07' => "Outdial for message Not +ification", '08' => "Invalid mailbox number or name", '09' => "Invalid Security Code", '10' => "System problem prevented acc +ess", '11' => "Outdial Page", '12' => "Called, left a message and callback page", '13' => "Called an +d left Page" ); print "Your Options Are:\n"; print "\n"; print "Search by Start Date = 'd'\n"; print "Search by Start Time = 't'\n"; print "Search by VM Mailbox Number = 'v'\n"; print "Search by Start Date & Time = 'b'\n"; print "Quit Search Utility? = 'q'\n"; print "\n"; do { print "Select Your Option:> (d, t, v, b, q)"; #Choose a letter chomp($choice = <STDIN>); } until ($choice =~ /^[DdTtVvBbQq]/); if ($choice =~ /^[Dd]/) { print "Enter Date in Form:(01/11/19-01/11/22)\n"; $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 "Begin Date: $datemin-End Date: $datemax\n"; print "Matches\n-------\n"; open(FILE, "/home/dhagens/MVP.dump.capture.file"); while (<FILE>) { my @matched = /(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d{2}\/\d{2}\/\d{ +2})\s(\d{2}\:\d{2}\:\d{2})\s(\d+)\s(\S+)\s(\d+)\s(\d+)\s(\d{2}\:\d{2} +\:\d{2})\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\w+)\s(\d+)\s(\d+)\s(\d+)\s(\d ++)\s(\d+)\s(\d+)\s(\d+)\s(\S+)/; if (@matched) { $matched[1] = "*System ID String($matched[1])*"; $matched[5] = "*Call Start Time:($matched[5])*"; $matched[6] = "*Primary Activity Code:($PAC{$matched[6]})*" +; $matched[7] = "*Mailbox number of sender or subscriber:($ma +tched[7])*"; $matched[9] = "*Disconnect Code:($DC{$matched[9]})*"; $matched[10] = "*Elapsed Time of Call:($matched[10])*"; $matched[11] = "*Number of Messages Received:($matched[11]) +*"; $matched[12] = "*Number of Messages Sent:($matched[12])*"; $matched[15] = "*Type of Call:($TOC{$matched[15]})*"; if (($matched[4] ge $datemin) && ($matched[4] le $datemax)) + { $matched[4] = "*Start Date of Call:($matched[4])*"; print join( ' ', @matched ), "\n\n"; } } } } if ($choice =~ /^[Tt]/) { print "Enter Time in Form:(00:00:40-00:00:50)\n"; $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 "Begin Time: $timemin-End Time: $timemax\n"; print "Matches\n-------\n"; open(FILE, "/home/dhagens/MVP.dump.capture.file"); while (<FILE>) { my @matched = /(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d{2}\/\d{2}\/\d{2} +)\s(\d{2}\:\d{2}\:\d{2})\s(\d+)\s(\S+)\s(\d+)\s(\d+)\s(\d{2}\:\d{2}\: +\d{2})\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\w+)\s(\d+)\s(\d+)\s(\d+)\s(\d+) +\s(\d+)\s(\d+)\s(\d+)\s(\S+)/; if (@matched) { $matched[1] = "*System ID String($matched[1])*"; $matched[4] = "*Start Date of Call:($matched[4])*"; $matched[6] = "*Primary Activity Code:($PAC{$matched[6]})*"; $matched[7] = "*Mailbox number of sender or subscriber:($matc +hed[7])*"; $matched[9] = "*Disconnect Code:($DC{$matched[9]})*"; $matched[10] = "*Elapsed Time of Call:($matched[10])*"; $matched[11] = "*Number of Messages Received:($matched[11])*" +; $matched[12] = "*Number of Messages Sent:($matched[12])*"; $matched[15] = "*Type of Call:($TOC{$matched[15]})*"; if (($matched[5] ge $timemin) && ($matched[5] le $timemax)) { $matched[5] = "*Call Start Time:($matched[5])*"; print join( ' ', @matched ), "\n\n"; } } } } elsif ($choice =~ /^[Vv]/) { print "Enter VM Number in Form:(92a7a77248)zeros will be a's\n"; chomp($msisdn = <STDIN>); print "Matches\n-------\n"; open(FILE, "/home/dhagens/MVP.dump.capture.file"); while (<FILE>) { my @matched = /(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d{2}\/\d{2}\/\d{2} +)\s(\d{2}\:\d{2}\:\d{2})\s(\d+)\s(\S+)\s(\d+)\s(\d+)\s(\d{2}\:\d{2}\: +\d{2})\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\w+)\s(\d+)\s(\d+)\s(\d+)\s(\d+) +\s(\d+)\s(\d+)\s(\d+)\s(\S+)/; if (@matched) { $matched[1] = "*System ID String($matched[1])*"; $matched[4] = "*Start Date of Call:($matched[4])*"; $matched[5] = "*Call Start Time:($matched[5])*"; $matched[6] = "*Primary Activity Code:($PAC{$matched[6]})*" +; $matched[9] = "*Disconnect Code:($DC{$matched[9]})*"; $matched[10] = "*Elapsed Time of Call:($matched[10])*"; $matched[11] = "*Number of Messages Received:($matched[11]) +*"; $matched[12] = "*Number of Messages Sent:($matched[12])*"; $matched[15] = "*Type of Call:($TOC{$matched[15]})*"; if ($matched[7] =~ $msisdn) { $matched[7] = "*Mailbox number of sender or subscriber:($ +matched[7])*"; print join( ' ', @matched ), "\n\n"; } } } } elsif ($choice =~ /^[Bb]/) { print "Enter Date in Form:(01/11/19-01/11/22)\n"; $range = <STDIN>; print "Enter Time in Form:(00:00:40-00:00:50)\n"; $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 "Begin Date: $datemin-End Date: $datemax\n"; print "Begin Time: $timemin-End Time: $timemax\n"; print "Matches\n-------\n"; open(FILE, "/home/dhagens/MVP.dump.capture.file"); while (<FILE>) { my @matched = /(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d{2}\/\d{2}\/\d{2} +)\s(\d{2}\:\d{2}\:\d{2})\s(\d+)\s(\S+)\s(\d+)\s(\d+)\s(\d{2}\:\d{2}\: +\d{2})\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\w+)\s(\d+)\s(\d+)\s(\d+)\s(\d+) +\s(\d+)\s(\d+)\s(\d+)\s(\S+)/; if (@matched) { $matched[1] = "*System ID String($matched[1])*"; $matched[6] = "*Primary Activity Code:($PAC{$matched[6]})*"; $matched[9] = "*Disconnect Code:($DC{$matched[9]})*"; $matched[10] = "*Elapsed Time of Call:($matched[10])*"; $matched[11] = "*Number of Messages Received:($matched[11])*" +; $matched[12] = "*Number of Messages Sent:($matched[12])*"; $matched[15] = "*Type of Call:($TOC{$matched[15]})*"; if (($matched[4] ge $datemin) && ($matched[4] le $datemax) && + ($matched[5] ge $timemin) && ($matched[5] le $timemax)) { $matched[4] = "*Start Date of Call:($matched[4])*"; $matched[5] = "*Call Start Time:($matched[5])*"; print join( ' ', @matched ), "\n\n"; } } } } elsif ($choice =~ /^[Qq]/) { $SIG{INT}; }
And there it is! What the code does in a nutshell is just go through a text file and search by date or time or both or just a number. Well thakyou Monks it's been a pleasure. Now I go off to College.

The Brassmon_k


Comment on Re: Re: Is it Possible to match contents in hash via a Regex?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://136897]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2014-08-20 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (113 votes), past polls