Sigh.<br><br>Regarding the accusation that I did not read the docs. Here's an excerpt from man perlre (the highlights are mine):<br><br><div style="margin-left:40px"> Warning on \1 Instead of $1<br> Some people get too used to writing things like:<br>
<br> $pattern =~ s/(\W)/\\\1/g;<br><br> This is <u><i><b>grandfathered</b></i></u> (for \1 to \9) for the RHS of a substitute to avoid shocking the sed addicts, but it's<br> a dirty habit to get into. That's because in PerlThink, the righthand side of an "s///" is a double-quoted<br>
string. "\1" in the usual double-quoted string means a control-A. The customary Unix meaning of "\1" is<br> kludged in for "s///". However, if you get into the habit of doing that, you get yourself into trouble if<br>
you then add an "/e" modifier.<br><br> s/(\d+)/ \1 + 1 /eg; # causes warning under -w<br><br> Or if you try to do<br><br> s/(\d+)/\1000/;<br><br> You can't disambiguate that by saying "\{1}000", whereas you can fix it with "${1}000". The operation of<br>
interpolation should not be confused with the operation of matching a backreference. Certainly they mean<br> two different things on the left side of the "s///".<br></div><br>So you see, \1 in the replace is not deprecated, it is grandfathered. Everybody, feel free to keep using it, although it's use may cause reviewers of your code to point and stare, perhaps gesticulate.<br>
<br>stylistically, I'd say if you're using \1 on the match side, don't switch to $1 on the replace side. It's confusing.<br><br>As for being greatly mistaken about \1 and $1, I think not. \1 and $1 are slightly different beasts on the match side of
an s/// regex. They both work, and are not deprecated. On the replace
side, \1 and $1 are equivalent, there is no deprecation of \1. I've made specific statements about how \1 and $1 behave on the match side so as to better understand their differentiation. I've posted tested examples as well, and snippets of the documentation. So, Uri, what exactly is it that I'm greatly mistaken about?<br>
<br>I am not sure what to make of the bottom posting remark. Perhaps it doesn't belong in this thread?<br><br>fyi, The code snippets I posted were tested with perl 5.14.<br><br>-rob<br><br><div class="gmail_quote">On Sun, Oct 28, 2012 at 12:02 PM, Uri Guttman <span dir="ltr"><<a href="mailto:uri@stemsystems.com" target="_blank">uri@stemsystems.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 10/28/2012 06:45 AM, Rob Janes wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
ok, if you don't believe me when I say it doesn't work, try it yourself<br>
then.<br>
<br>
</blockquote></div>
i haven't tried it as i said i didn't test it.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
[robj@rj-ul80vt ~]$ perl -e '$x = "one \t\t two"; print "$x\n"; $x =~<br>
s/(\s)$1+/\1/; print "$x\n";'<br>
one two<br>
one two<br>
[robj@rj-ul80vt ~]$ perl -e '$x = "one \t\t two"; print "$x\n"; $x =~<br>
s/(\s)\1+/\1/; print "$x\n";'<br>
one two<br>
one two<br>
<br>
notice that the usage of $1 resulted in a mixed string of whitespace being<br>
substituted. only the tabs should have been substituted, not everything.<br>
<br>
therefore, the $1 in the matching regex resolved to \s not space.<br>
<br>
</blockquote></div>
please read the docs. you are greatly mistaken about \1 and $1. you keep using \1 in the replacement where it doesn't belong. why it seems to work is another story. when i get to playing with the code i will figure it out. too busy today.<br>
<br>
and learn to bottom post too.<span class="HOEnZb"><font color="#888888"><br>
<br>
uri<br>
<br>
<br>
<br>
<br>
</font></span></blockquote></div><br>