in reply to Re: use of constants in regex substitutions?
in thread use of constants in regex substitutions?

I'd prefer to write:
MIF_EXTENSION => "[.]mif", TXT_EXTENSION => "[.]txt",
Then you don't have to wonder how many backslashes you need, and you don't have to use \Q, \E each time you use MIF_EXTENSION or TXT_EXTENSION.

Abigail

Replies are listed 'Best First'.
Re: Re: use of constants in regex substitutions?
by edan (Curate) on Sep 23, 2003 at 15:15 UTC

    Ah, but it doesn't appear that these constants are only being used as the match expression of a regex. For instance, the original code posted is trying to substitute TXT_EXTENSION for MIF_EXTENSION. I don't think the intent is to turn ".txt" into "[.]mif".

    --
    3dan

      Oh, sure, but then your first suggestion, putting them in single quotes isn't going to work either, because I don't think the intent is to turn '.txt' into '\.mif'.

      Abigail

        Quite right! Good thing I recommended the second option... ;-). I maintain that \Q is the right way to do it.

        --
        3dan