Thx to everyone on this. I chucked the system date function I originally wrote and used strftime and localtime. Guess I haven't read that part of the perl book yet ;-)

So when I wrote the program originally, was it populating $date incorrectly? I'm hoping to understand why it didn't work in the first place.

FYI... %e would have blank padded what I was looking for. The access logs in apache have the / between the month and day. The error logs however would have worked with %e since they space out the month& day.

Thx again!!



John W. Krahn wrote:

U235sentinel wrote:


While I've already done this with a simple shell script using grep, I
was trying to figure out how I can do the same thing in perl.

I have an access_log  from my apache web server and while I can manually
enter a date for my pattern match (which works fine), I can't seem to
get it automated properly.  I suspect the $date variable may be passing
`date +%d/%b` instead of  26/Dec to the pattern matching if statement.

FYI...  when I run the program I pass the name of the file I want parsed
( example:   code.pl access_log )

Any thoughts on my mistake?

Thx

---------------------

Script I'm using.

#!/usr/bin/perl



use warnings; use strict;




$date=`date +%d/%b`;



There is no need to run an external program to get the date:


my @mons = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
my $date = sprintf '%02d/%s', (localtime)[3], $mons[ (localtime)[4] ];

Or:

use POSIX 'strftime';
my $date = strftime '%d/%b', localtime;




print "\n";
print "Current search pattern is $date";
print "\nStarting parse routine...\n\n";
while (<>) {
if (m|$date|) {



This should work. Are you sure that the day of the month format is %d and not %e?




print $_;
} else {
# print "No match.\n";
}
}




John




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




Reply via email to