Update: As MeowChow's pointed out to me, it's not necessary to \Q\E within the substitition part of s/// for this to work, as well as in m// strings as well; code snippet has been updated to reflect this. Mainly, if you do so, realize any special symbols ('.', '{', '}', etc) wil be quoted (eg '.' to '\.'), if you do include the \Q\E.
use constant TEST => 3; my $string = "123456"; $string =~ s/\Q@{[ TEST ]}\E/9/; print $string, "\n"; # 129456 $string =~ s/2/@{[ TEST ]}/; print $string, "\n"; # 139456
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using constants inside regex
by MeowChow (Vicar) on Jul 02, 2001 at 07:20 UTC | |
|
Re: Using constants inside regex
by BrentDax (Hermit) on Jul 07, 2001 at 01:16 UTC |