Using Path::Tiny. It has a method: children which could be used as:
@paths = path("/tmp")->children( qr/\.txt$/ );
If an optional qr// argument is provided, it only returns objects for child names that match the given regular expression. Only the base name is used for matching
So the
@paths = path("/tmp")->children( qr/\A(foo|bar|baz)\z/ );
will return either foo
bar
baz
files found in the /tmp
.
I need the opposite, want any file but NOT the (foo|bar|baz)
ones.
The following could filter out the unwanted ones,
@paths = grep { $_->basename !~ /^(foo|bar|baz)$/ } path("/tmp")->children;
but wondering how to write the qr
for it.
So, the question: How to create the qr
expression for: any file but not foo|bar|baz
?
I tried the negative lookahead
path(...)->children( qr/\A (?!(foo|bar|baz)) \z/x );
but, it doesn't do what I think it should do :) - e.g. my regex is wrong.