in reply to use of constants in regex substitutions?
use constant {
MIF_EXTENSION => "\.mif",
TXT_EXTENSION => "\.txt"
};
This is not doing what you want it to. The backslash is interpreted when perl parses the double-quoted string, so the values end up being '.mif' and '.tif' (since \. has no special meaning in a double-quoted string, as does, say \n). Your regexp will then match any character followed by txt. You need to either:
$s1 =~ s/\Q${\TXT_EXTENSION}\E/MIF_EXTENSION/e;
I personally recommend #2, since you want to match literal text, without metacharacters, and that's what \Q is for.
Also, you should follow Zaxo's advice, and not dmitri's, since one will work, and one won't (you guess which is which).
--
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: use of constants in regex substitutions?
by Abigail-II (Bishop) on Sep 23, 2003 at 15:04 UTC | |
by edan (Curate) on Sep 23, 2003 at 15:15 UTC | |
by Abigail-II (Bishop) on Sep 23, 2003 at 15:27 UTC | |
by edan (Curate) on Sep 23, 2003 at 15:38 UTC |