Re: yet another regex On 5/11/07, Tom Phoenix  wrote:
> On 5/11/07, Steve Finkelstein  wrote:
>
> > sflinux themes # echo 500 | perl -ple 's|(\\d)|length(9 x $1)|eg;'
> > 500
>
> > essentially, (\\d) should match just the '5' in 500. that puts $1 == the
> > literal 5. so you take length(9 x 5) which is nine repeated 5 times, and
> > the length of that is 5. That replaces the 5 with a ... 5?
> >
> > Is my logic correct on this?
>
> I think you've got it, except it doesn't stop with the 5. Unless I'm
> missing something, that substitution means the same thing as this
> simpler one:
>
>     s#(\\d)#$1#g
>
> Unless the value of $1 is useful, it's hard to see what good this
> does. It replaces each digit with itself. As side effects it affects
> all the match variables, and it stringifies its target.
>
> Did you find that piece of code somewhere? Do you know what its author
> was trying to do?
>
> --Tom Phoenix
> Stonehenge Perl Training

Beyond obfuscation, I can only think of one reason to write something
like that: un-tainting.  But even then it is bad regex for that since
it doesn't validate anything.

-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/


