On Wed, Oct 06, 2004 at 02:12:58PM -0500, Ed McLain wrote:
> my $date = `date +%F`;
> my $hour = `date +%H`;
> my $min  = `date +%M`;
> chomp($date);
> chomp($hour);
> chomp($min);
> 
> $min =~ /([0-9])([0-9])/;
> my $mf = $1;
> my $ml = $2;

How about this:

($sec, $min, $hour, $day) = localtime();

Much shorter, simpler, more secure and uses far less CPU and RAM than
forking to an external command three times.

> 
> my $ms = 0;
> my $me = 4;
> 
> while ( <LOG> ) {
>       if ( /^$date $hour:$mf[$ms-$me]/ ) {
>               if ( /status: / ) {
>                       print $_;
>               }
>       }
> }
> 
> --End Snipet--
> 
> Now the one that is giving me hell is the:
> 
> if ( /^$date $hour:$mf[$ms-$me]/ ) {
> 
> This will for instance match '2004-10-06 14:4' however it will not do
> '2004-10-06 14:40' directly.  Can anybody see what I'm doing wrong?

How about this:

$ms = "0";      # Note these are strings because they are for regexp matching
$me = "4";
$match = sprintf("%02d %02d:%d[%s-%s]", $day, $hour, $min / 10, $ms, $me)
print STDERR "Matching $match\n";       # Useful for debugging
while (<LOG>) {
  print if /^$match/ and /status: /;
}

Hope that helps,
                Andrew
-- 
mailto:[EMAIL PROTECTED]                         Andrew Pam
http://www.xanadu.com.au/                       Chief Scientist, Xanadu
http://www.glasswings.com.au/                   Partner, Glass Wings
http://www.sericyb.com.au/                      Manager, Serious Cybernetics

Reply via email to