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:

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...
Any ideas? I'm still hacking around, but this would be really ideal for my program. Am I on the right track? Thanks ^^

In reply to regular expression for log file date ~ questions and ideas ~ by perl_geoff

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.