perl_geoff has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I have a program that grabs a log file and parses it for errors. I am curious as to how to use a regular expression to grab only the most current log file...for example if my log files contain the date in their name like 'logfilename_20061201_LOG', I would like to make my program only grab the log with the date string greater than or equal to the current date. I was thinking of using a regex for the logfilename string, but not sure how to write it (still new to regex.)
My second question: Is there a way to then take the system date, convert it into a numerical format like 20061201 and then say "only open the log file that matches the log filename with the date greater than or equal to the system date in numerical format like 20061201?" My pseudocode:
Any ideas? I'm still hacking around, but this would be really ideal for my program. Am I on the right track? Thanks ^^my $logpath = "\\\\directory\\log\\"; my $logfile = "logfilename_20061201_LOG"; my $date = "20061201"; my $log = "$logpath$logfile"; open LOG, "<", $log or die "Cannot open $log for read :$!"; while (<LOG>) { if ($log =~ /$dateregex/) { etc...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regular expression for log file date ~ questions and ideas ~
by MonkE (Hermit) on Dec 01, 2006 at 18:57 UTC | |
by perl_geoff (Acolyte) on Dec 01, 2006 at 19:19 UTC | |
by Firefly258 (Beadle) on Dec 02, 2006 at 05:41 UTC | |
by perl_geoff (Acolyte) on Dec 04, 2006 at 14:35 UTC | |
by Firefly258 (Beadle) on Dec 04, 2006 at 16:53 UTC | |
|
Re: regular expression for log file date ~ questions and ideas ~
by ww (Archbishop) on Dec 01, 2006 at 18:43 UTC | |
|
Re: regular expression for log file date ~ questions and ideas ~
by Fletch (Bishop) on Dec 01, 2006 at 18:54 UTC | |
|
Re: regular expression for log file date ~ questions and ideas ~
by graff (Chancellor) on Dec 02, 2006 at 17:17 UTC |