Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: use of constants in regex substitutions?

by Abigail-II (Bishop)
on Sep 23, 2003 at 15:04 UTC ( [id://293519]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://293519]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found