in reply to Re^9: Restrict file search within current filessystem using wanted subroutine
in thread Restrict file search within current filessystem using wanted subroutine

Hi Hauke,

As suggested, it is good to use an exact match to exclude specific file.

return if $File::Find::name eq '/var/log/test.out';

But now if I want to exclude more than one file, can I use an OR condition to the above line. Else for every exclusion I have to write a new exclusion as below:

return if $File::Find::name eq '/var/log/test.out'; return if $File::Find::name eq '/var/log/new.out';

Regards, Madparu

  • Comment on Re^10: Restrict file search within current filessystem using wanted subroutine

Replies are listed 'Best First'.
Re^11: Restrict file search within current filessystem using wanted subroutine
by haukex (Archbishop) on May 18, 2016 at 19:37 UTC

    Hi Madparu,

    For exact matches you could use a hash. Before your call to find add: my %EXCLUDES = map {$_=>1} ( '/var/log/test.out', '/var/log/new.out', ); and change your condition to return if $EXCLUDES{$File::Find::name};. The first piece of code builds a hash from a list of strings, where the keys of the hash are the strings and the values are just 1, and then the condition checks to see if a hash entry with the key $File::Find::name exists and has a true value. An alternative might be to switch back to regex matches, e.g. return if $File::Find::name =~ m{^/var/log/(?:test|new)\.out$};

    Considering that I've been writing your script for you piece by piece, now might be a good time to invest some time into learning more about Perl. Have a look at perlintro, Getting Started with Perl, http://learn.perl.org/ or perhaps the books Learning Perl or Modern Perl (the latter is free). And if you run into questions or trouble, of course feel free to ask here - see How do I post a question effectively?

    Hope this helps,
    -- Hauke D