First, your commented if clause would work if you changed your "or" to an "and" - a valid choice must be both not "." and not "..". Also, in regular expressions, . is a wildcard character, so they will match far more than you intend - see perlretut.

If you wanted to avoid some layers of conditional nesting, you could use next as a short circuit on your file tests. Something like:

opendir(GPS,"$new_dir") or die "Cannot open directory"; my @GPS = readdir(GPS); closedir(GPS); foreach my $kid (@GPS){ next if $kid eq "."; next if $kid eq ".."; next if not defined $kid; next if $kid =~ /\.bak$/; next if $kid =~ /\.txt$/; open KID , '<', "$new_dir\\$kid" or die "Open failure on $kid: $!" +; my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ct +ime,$blksize,$blocks) = stat(KID); my $data = <KID>; close KID; if (defined($data)){ my @data = split(" ", $data); my $diff = time-$mtime; if ($diff >= 3600){ unlink($kid); } elsif ($diff >= 20){ } } }

Update: I forgot to mention you should be checking whether open succeeds or not. As well, you may consider checking out the file tests available in -X.


In reply to Re: Catching . .. in file listing by kennethk
in thread Catching . .. in file listing by deadpickle

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.