John W. Krahn wrote:
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
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. Is there any speed
advantage in doing that by any chance?(vs just pushing it direclty to
@bad as my original code indicated).
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.
thanks guys!!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/