You could change your conditional as follows:

if ($entry5 ne $name && $entry5 !~ m/\.log$/) { # ...

You have this, currently: $entry5 ne '<*.log>', which doesn't really make sense. You clearly are not looking for a file named <*.log> but you are specifying exactly that within single quotes, which prevent the glob operator from doing anything useful. Additionally you don't really need the glob operator, they way you are testing the files.

There's another puzzler in your code as well: What filename would match $name . '.log' but would not match *.log or m/\.log$/? What I'm getting at is that there doesn't seem to be any good reason to test explicitly for $name, since the part of the conditional to the right of the && operator would already catch everything that ends in .log.

One thing also to bring up: You could probably avoid the readdir and while loop entirely by using the glob operator correctly:

if (-e 'abc' && -d _) { foreach my $entry (<*.log>) { print OUTPUT ":E: $entry5 is extra file/dir \n"; } }

This may or may not be exactly what you're after, but it's what your code seems to be trying to do.


Dave


In reply to Re: File searching * by davido
in thread File searching * by michael99

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.