Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: pattern match or key problem

by brassmon_k (Sexton)
on Jul 11, 2001 at 19:12 UTC ( #95714=note: print w/ replies, xml ) Need Help??


in reply to pattern match or key problem

This is brassmonk, I figured it out. I had a big (DA). Okay in the line which has "if (($2 >= $min) && ($2 <= $max)) {"

Well I tried "ge" in both of them prior to my post on accident I forgot to use "le" in the other. As soon as I did that it worked because I forgot that "ge" and "le" work with strings and "<=" or ">=" work with numbers. Anyway here's the revised script. Granted it's not everything I want yet but it's perty cool right now still working on it. Going to turn it into a CGI after I get the blasted thing to do what I want.

#!/usr/bin/perl -w 
use strict; 
my %mylist; 
my $min; 
my $max; 
my $range; 
my $line; 
# get the range (in this throwtogether it must be entered 
# with no spaces in the form HH:MM:SS.TS-HH:MM:SS.TS) 
# Get the range 
$range = <STDIN>; 
# Break up the range 
($min, $max) = split /-/, $range; 
# Squeeze out leading and trailing spaces 
$min =~ s/^\s+//; 
$min =~ s/\s+$//; 
$max =~ s/^\s+//; 
$max =~ s/\s+$//; 
# Open the datafile and break into fields 
open(FILE, "mon402.log");
while (<FILE>) {
if (s/<(.*?)>/TEXT/) {
if ($_ =~ m/(\d+\-\w+\-\d+)\s(\d{2}\:\d{2}\:\d{2}\.\d{2})\s+(\w*)/) {
# Push the restricted range of times onto a hash of arrays 
# keyed on the time field 
if (($2 ge $min) && ($2 le $max)) { 
push(@{$mylist{$2}}, $_); 
}
      }  
          } 
              }  
my @keys = sort (keys %mylist); 
foreach my $key (@keys) { 
foreach my $thing (@{%mylist}{$key}){ 
foreach my $it (@$thing) { 
print "$it\n"; 
last;
      } 
   } 
}
I did a few extra thingies. Anyway this is an SMS message log for cell phones and one of the new things is I eliminated customers text message text by making it say TEXT because it's a privacy liability and our company got sued because one of our customer care reps was reading them (To bad for him, he got the boot) Anyway now all it says is TEXT for the text(I love it) if (s/<(.*?)>/TEXT/) { I also improved the pattern match line. It's uglier than last time but it does see the fields, I like it when it looks cryptic like that! I had some test prints (print $1, $2, etc.) in there before to test if it sees separate fields and it did find the fields. (I love this stuff it's fun) So everything is cool now. Thanks for the help big time though. You people in this forum oops "monks" are so good at perl. I'm getting better but you guys rule at this perl. I'll get there someday. Anywho THANX!
DMH
brassmonk
Sorry I have no clever annotation or quote to spew out at the moment.


Comment on Re: pattern match or key problem

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-12-21 19:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (107 votes), past polls