Michael Alipio am Sonntag, 21. Januar 2007 04:08:
> Hi,

Hi Michael

> my $string = 'vd=root,status=';
>
> #Now, I want to transform it into:
> 'vd=root;status='
> #That is replace the comma(,) between root and status with semicolon (;);
>
> $string =~ s/vd=\w+(,)/;/;
> print $string,"\n";
>
> #And it prints:
>
> ;status=
>
> Can you tell me why it has ate up vd= as well?

Because everything matched - that is: vd=\w+(,) - is replaced with the 
semicolon.

You seem to misunderstand the meaning of the capturing parenthesis '()' on the 
left part of the substitution: They do not indicate the part of the string 
that is to be replaced; replaced is what the left side of the substitution 
matches.


> And how to get around with it..

One way is:

$string =~ s/(vd=\w+),/$1;/;

There are several man pages, where also the capturing parenthesis and the $1..
$n variables are explained:

perldoc perlre
perldoc perlretut
perldoc perlrequick

Hope this helps!

Dani

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to