in reply to calling regular expressions returned by functions?

Its not pretty, but this works:

use constant DOT => qr[\.];; print grep $_ =~ DOT, qw[ a b c . d e f];; .

Though it is really hard to see the benefit of making constants of those particular regex.

It's not like they are going to change anytime soon, and if they did, then you'd want to change their names also, which means you'd have to edit the place of use as well anyway.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: calling regular expressions returned by functions?
by Anonymous Monk on Mar 29, 2012 at 18:55 UTC

    Agreed as far as the directory semantics staying the same.

    However, the question is larger than just directory filtering. What constants gain is lessening the chance that a regular expression gets changed in one location when it needs to be changed in all locations, or it gets changed incorrectly in a code branch which isn't executed often or unfortunately tested. I only used directory filtering as an example.

    Thanks for your contribution.