<p dir="ltr">$1 doesn't work.</p>
<p dir="ltr">\1 is the characters matched while $1 is the pattern matched.</p>
<p dir="ltr">It only matters if u want to match pure string.</p>
<p dir="ltr">Btw careful with the \n matching.</p>
<div class="gmail_quote">On Oct 27, 2012 6:51 PM, "Uri Guttman" <<a href="mailto:uri@stemsystems.com">uri@stemsystems.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 10/27/2012 06:19 PM, Chris Jones wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thank Stuart, I did end up using $File::Find::dir, very helpful.<br>
<br>
New question. I would like to replace multiple spaces with single<br>
spaces and multiple end of line with a single end of line.<br>
<br>
I thought this might work:<br>
$expression =~ s/(\s+)/\1/g; # puts back what it found<br>
<br>
So I tried<br>
$expression =~ s/(\s)/\1\s/g;<br>
</blockquote>
<br>
someone else gave you a decent solution but i want to clear up a misconception you have. the right side of s/// is a replacement string and \s is only a regex shortcut for white space. putting \s there will only give you a 's' char in the replacement. also \1 is not meant to be used in the replacement but only in the regex. $1 is the correct thing in the replacement. \1 is supported for backwards compatibility.<br>
<br>
another and likely better solution is to use tr///. this code will replace any run of space, \t, \r\n with a single one of each.<br>
<br>
tr/ \t\\n\r//s<br>
<br>
the replacement pattern will be duplicated from the left side and the /s modifier will squeeze them to 1 char. if you want to make any \r or \n runs be squeezed to a single \n you need an explicit replacement part:<br>
<br>
tr{ \t\n\r}{ \t\n\n}s<br>
<br>
i switched the delims as there were too many /\ leaning toothpicks.<br>
<br>
uri<br>
<br>
______________________________<u></u>_________________<br>
toronto-pm mailing list<br>
<a href="mailto:toronto-pm@pm.org" target="_blank">toronto-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/toronto-pm" target="_blank">http://mail.pm.org/mailman/<u></u>listinfo/toronto-pm</a><br>
</blockquote></div>