Hi Scott, Francesco.

Scott R. Godin wrote:
> Francesco Del Vecchio wrote:
>
> > suppose this:
> > ======================================
> > $string 'I saw Roger and I said :roger? what the @*$!';
> >
> > $var1 = "roger? what the @*$!";
> > $var2 = "Hi roger...nice to meet you";
> >
> > $string=~ s/$var1/$var2/;
> > =======================================
> >
> > I'm having problems....due (i suppose) to the special chars in the
> > $var1 string the s/// don't match anything.
> > What can I do to?
>
> s{\Q$var1\E}{$var2} is usually what you want, except that may very
> well 'quote' out the $ in $var.

I guess you mean $var2? The replacement expression will
only be interpolated once. Any variable names embedded in the
contents of $var2 will be copied verbatim.

> I suspect what you really want is
>
> $var1 = qr{roger? what the @*$!};

This won't work, I'm afraid. The $! will be interpolated
unless the delimiters are single-quotes:

    print (my $var1 = qr{roger? what the @*$!});

output

    (?-xism:roger? what the @*)

> ( perldoc -f qr ) (perldoc perlre) and (perldoc perlop) for more
> details.

Maybe what is wanted is:

    $var1 = quotemeta q{roger? what the @*$!};

which is the equivalent of the \Q...\E construct, but
applicable to an existing string.

HTH,

Rob






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to