I have a routine that searches a directory and it's sub directories for files that are older than five days. All is working great when I use my perl program on windows or UNIX Platforms. But now I need to have an additional check that the file also starts with the letter "L" or the word "Log". Any time I add this additional check in my sub routine no files are found at all, so I have something wrong. Here is what I have that works:
{ find (sub {my $filename = $File::Find::name; if ( -f $filename ) { my $filetime = (stat "$filename")[9]; my ($sec, $min, $hour, $day, $month, $year) = (localtime($filetime +))[0,1,2,3,4,5]; if ($now - $fivedaystime > $filetime){ my $mm = $month+1; my $yy = $year+1900; open (LOGFILE, '>>', $script_auditlog) or die "Could not open fi +le '$script_auditlog' $!"; print LOGFILE "$filename last modified on $mm\/$day\/$yy $hour\: +$min\:$sec was removed.\n"; push (@file_list, $filename); } } }, $pslog_directory); close LOGFILE; }
To accomplish what I need I was trying to do this:
if ( -f $filename && $filename =~ /^Log*/ )
Or I tried this:
if ( -f $filename && $filename =~ /^L/ )
The files in the directory that is searched look like this:
Log.txt.20151102 Log.txt.20151103 Fsvrcom1.trc Fsvrcom2.trc
I need to leave the files that don't start with "L" alone. Any help is greatly appreciated.

In reply to File name search with regex by oldenuf2no

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.