John W. Krahn wrote:
Richard Lee wrote:
sub shove_it {
my $start = time_this(scalar localtime( ( time() - ( 60 * 60 )
) ));
What does the time_this() function do?
sub time_this {
my $chunli = join(' ', ( split( /\s+/, $_[0]))[1,2,3]);
if ($chunli =~ s/^(\S\S\S)(\s)(\d\d\s)(\d\d:).+$/$1$2$3$4/g) {
return $chunli;
} elsif ($chunli =~ s/^(\S\S\S)(\s)(\d\s)(\d\d:).+$/$1$2 $3$4/g) {
return $chunli;
} else {
print "There was a problem\n";
exit 0;
}
}
open my $source, "<", "/var/log/server.log"
or die "Could NOT open /var/log/server.log: $!";
while ( <$source> ) {
chomp;
next if ! /^$start/;
next if ! m{
.+\s+D\s+
.+ is greedy and will match everything in $_ and will then have to
backtrack to match \s+D\s+. The leading \s+ will only ever match one
\s because .+ is greedy. This only makes sense if you have multiple
occurrences of this whole pattern and you only want to match the last
occurrence and capture their values but you are not using capturing.
udp\s+
\d+\.\d+\.\d+\.\d+\s+
\d+\.\d+\.\d+\.\d+\s+
\d+\s+\d+\s+
.+
The .+ at the end is superfluous
}xms;
You are using the /m option which says that ^ and $ should match the
beginning and end of a line but you are not using ^ or $ in the
pattern. You are using the /s option which says that . should match a
newline as well as every other character but you are not trying to
match a newline nor do you really need . in the pattern at all.
push @bad, join('_', ( split( /\s+/, $_))[10,12,11,13,9,8]);
If some of the patterns in the match operator above are the same as
the ones that you are split()ing out of the string then you should
just capture and use them directly instead of processing the line again.
}
close $source;
}
You are not returning the contents of @bad and you are not passing in
the name of the file to open so I assume that this is in a subroutine
because you are calling it many times in your program?
John
Yes, it is sub
I am trying out your suggestion right now. Will report back.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/