in reply to File finder

## # This isn't part of the core logic: we're just trying to make regexp # generation easy for admins with weak regex chops # The original use case used regexps to select files of interest. my @name_patterns = qw { *.conf$ ^ho ^net }; my @name_regexps = map { s/\./\\./g; s/\*/(\.+)?/g; qr {$_}; } @name_patterns;

The  * glob pattern can match zero characters but you are replacing it with  (\.+)? which has to match at least one character.   Perhaps you want to use this instead:  s/\*/(?s:.*?)/g;   And don't forget the  ? glob pattern which must match one character:  s/\?/(?s:.)/g;

Replies are listed 'Best First'.
Re^2: File finder
by mpeever (Friar) on Oct 19, 2008 at 15:37 UTC

    You're absolutely right: the glob replacement is incorrect. Worse, it worked "close enough" that I managed to think I had done it right. I appreciate you pointing that out, I'll work on fixing that.

    To be perfectly honest, building regexps on the fly seemed clever at the time, but I'm not really sure it bought us that much. I was thinking in terms of typical shell usage, where *.conf refers to any file ending in ".conf". But the reality is, /\.conf$/ matches that already, with no need to explicitly name a wildcard. Additionally, I ended up using anchors in the strings, which is precisely what I was trying to avoid.

Re^2: File finder
by mpeever (Friar) on Oct 23, 2008 at 23:30 UTC
    Thanks again for the regex suggestions, I made them and they're exactly what I was going for.