Richard Lee wrote:
John W. Krahn wrote:

Or you could do something like this:


use POSIX ();

use constant ONE_HOUR => 60 * 60;

my $file_name = '/var/log/server.log';


my @bad = do {
my $start = qr/@{[ POSIX::strftime( '%b %e %H:', localtime time - ONE_HOUR ) ]}/; open my $SOURCE, '<', $file_name or die "Could NOT open $file_name: $!";
    my @lines;
    while ( <$SOURCE> ) {
        next unless /^$start/
             and m{
                   \s
                   D
                   \s+
                   udp
                   \s+
                   (\d+\.\d+\.\d+\.\d+)
                   \s+
                   (\d+\.\d+\.\d+\.\d+)
                   \s+
                   (\d+)
                   \s+
                   (\d+)
                  }x;
        push @lines, "${1}_${3}_${2}_$4";
        }
    @lines;
    };

I will have to try out your POSIX solution as I have particular in adding space if date is single digits (April 3 gets additional space vs April 11 which does not). also, I will have to try it out the do { } as I don't have any experince w/ it.
I am assuming, @lines will be assign to @bad.

Yes.

Is there any speed advantage in doing that by any chance?(vs just pushing it direclty to @bad as my original code indicated).

Not that I know of, it is just another way to do it (TMTOWTDI) that provides a limited scope for the $SOURCE and $start variables

My code is about 60% done and working on matching them(results of comparing @bad and predefined hash).. once it's all done, I will provide it here for some constructive criticism as I am learning so much.

Always glad to help.   :-)


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