Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming that you've parsed the configuration file to get a list of extensions and ignored directories, you can build the regular expression as a string and then use the <code>qr</code> operator to compile it into a regular expression:</p> <pre><code>my @extensions = qw(avi flv mp3 mp4 wmv); # parsed from file my $pattern = '\.(' . join('|', @wanted) . ')$'; my $regex = qr/$pattern/; if ($file =~ $regex) { # do something } </code></pre> <p>The compilation isn't strictly necessary; you can use the string pattern directly:</p> <pre><code>if ($file =~ /$pattern/) { # do something } </code></pre> <p>Directories are a little harder because you have two different situations: full names and suffixes. Your configuration file will have to use different keys to make it clear which is which. e.g. "dir_name" and "dir_suffix." For full names I'd just build a hash:</p> <pre><code>%ignore = ('.svn' =&gt; 1); </code></pre> <p>Suffixed directories can be done the same way as file extensions:</p> <pre><code>my $dir_pattern = '(?:' . join('|', map {quotemeta} @dir_suffix), ')$'; my $dir_regex = qr/$dir_pattern/; </code></pre> <p>You could even build the patterns into anonymous subroutines to avoid referencing global variables:</p> <pre><code>my $file_filter = sub { $_ =~ $regex }; my $descend_filter = sub { ! $ignore{$File::Next::dir} &amp;&amp; ! $File::Next::dir =~ $dir_regex; }; my $iter = File::Next::files({ file_filter =&gt; $file_filter, descend_filter =&gt; $descend_filter, }, $directory); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload