Re: is \1 vs $1 a necessary distinction?
[email protected] (Bart Lateur) Thu, 28 Sep 2000 23:48:46 +0200
| Newsgroups | perl.perl6.language.regex |
|---|---|
| Organization | MediaMind |
| Message-ID | <[email protected]> |
On Wed, 27 Sep 2000 10:34:48 -0500, Jonathan Scott Duff wrote: >If $1 could be made to work properly on the LHS of s///, I'd vote for >that being The Way. I disagree, because \1 is different from a variable $foo in at least two ways: * $foo is compiled into /$foo/ before anything is matched. \1 is a repetition of what was just matched; this is dynamic interpolation instead of static. * if $foo contains metacharacters, they are treated as metacharacters. for example, if $foo is "a.b", then /$foo/ can match "axb". /\1/, OTOH, can only match the LITERAL string that $1 captured. With $foo='a.b', /($foo)!$foo/ and /($foo)!\1/ will not match the same set of things. "\1" is more like equivalent to "\Q$1\E". Therefore, I don't want $1 on the LHS to be the standard syntax. -- Bart.