Richard Lee wrote:

John W. Krahn wrote:
Richard Lee wrote:
John W. Krahn wrote:
Richard Lee wrote:
John W. Krahn wrote:

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?

Yes, it is sub

The question was: are you calling the subroutine once or calling it many different times?

it will be called only once.

@bad is global variable

If you are only calling it once why is it a subroutine at all?

does subroutine introduce additional delay?

All non-inlined subroutines introduce some delay, although that is not your problem as you are only calling it once.

I am trying to write a lot of perl and trying to organize my program in case I need to modulalize it.

It sounds like you should learn about object oriented programming.

Well, I just like having pretty much all function in sub.
Also trying to learn subroutine..

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;
    };




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