Richard Lee wrote:

sub shove_it {
     my $start = time_this(scalar localtime( ( time() - (  60 * 60 ) ) ));

What does the time_this() function do?


         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
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to