Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: File searching *

by davido (Cardinal)
on Mar 02, 2020 at 03:33 UTC ( #11113616=note: print w/replies, xml ) Need Help??

in reply to File searching *

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.


Replies are listed 'Best First'.
Re^2: File searching *
by michael99 (Acolyte) on Mar 02, 2020 at 04:29 UTC
    Thanks Dave for the comment. !~ m/\.log$/ is working. Apparently you bring up a good point where $name.".log" is extra effort while the right condition has been included it.

    For the suggestion to avoid reaadir and while loop, since I cannot sure which file would exist to be searched, and I need to print out whose additional files which not in the spec defined. How would I defined the condition in 'foreach' ?

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11113616]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2020-11-26 08:05 GMT
Find Nodes?
    Voting Booth?

    No recent polls found