in reply to Re: Re: constants within regular expression?
in thread constants within regular expression?

@{[MYTEST]} leaves out the all-important "quotemeta". In the OP's example, the literal text to match against was ".txt", and without quotemeta, '.' will match anything, instead of dot.


Dave


"If I had my life to live over again, I'd be a plumber." -- Albert Einstein

Replies are listed 'Best First'.
Re^3: constants within regular expression?
by Coruscate (Sexton) on Nov 26, 2003 at 06:43 UTC

    Ah, didn't even think about using ref/deref to do so. In that case, to match correctly:

    /\Q@{[EXTENSION]}\E\z/

Re: Re: Re: Re: constants within regular expression?
by sauoq (Abbot) on Nov 26, 2003 at 07:02 UTC
    @{[MYTEST]} leaves out the all-important "quotemeta".

    Well, to be fair, whether or not it is all important depends entirely on the behavior you want. Granted, the OP, probably did not want the dot in ".txt" to match anything; so he'd probably want to do it like /\Q@{[EXTENSION]}/ instead. But, someone else might want to use a constant like use constant FILEPATTERN => 'foo.*\.txt'; in which case he probably wouldn't want to quote his metacharacters.

    -sauoq
    "My two cents aren't worth a dime.";