#!/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!
In reply to Re: pattern match or key problem
by brassmon_k
in thread pattern match or key problem
by brassmon_k
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |