Re: Substituting in a group

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
Willem wrote:
) while (s/(")(.*?)"/\$2/) { substr(\$_,\$+[1]-1,\$+[2]-\$+[1]) =~ s/,/#/g }

Of course,
while (s/"(.*?)"/\$1/) { substr(\$_,\$-[1]-1,\$+[1]-\$-[1]) =~ s/,/#/g }
is slightly easier.

SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT

Re: Substituting in a group

Thanks for the great discussion - I learnt a few things.
One last question: what does \$ and [1] stands for in the above post in
"\$-[1]-1"? Where can I find more about that in perldoc?

Re: Substituting in a group

\$-[1] is the second element of the array @-, which is documented in
perlvar. The syntax is exactly the same as for \$a[1] or any other array.

Ben

--
I must not fear. Fear is the mind-killer. I will face my fear and
I will let it pass through me. When the fear is gone there will be
nothing. Only I will remain.
ben@morrow.me.uk                                          Frank Herbert, 'Dune'

Re: Substituting in a group

Found it here: http://perldoc.perl.org/perlvar.html#%40 -

Re: Substituting in a group

Willem wrote:

Or use a statement modifier:

substr( \$_, \$-[1] - 1, \$+[1] - \$-[1] ) =~ s/,/#/g while s/"(.*?)"/\$1/;

Or maybe:

/".*?"/ and substr( \$_, \$-[0], \$+[0] - \$-[0] ) =~ tr/,"/#/d;

And avoid using the substitution operator or capturing parentheses.

John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall