On Jun 13, Carl Rogers said:

>Good afternoon;
>I have a dumb question: I'm working with the following:
>
>$line = "Joe Doe 123 Main St. Sometown, USA";
>
>I have parsed the line to assign the values to the following variables:
>
>$fname = "Joe";
>$lname = "Doe";
>$addr = "123 Main St.";
>
>I'm trying to use the substitution operator to do something like:
>
>       $line =~ s/$fname $lname $addr//;               ## doesn't like this syntax
>
>So the value of $line now becomes "Sometown, USA".

It does work, with the data you've given us.  It doesn't work with the
data you have.  Use the \Q...\E escape sequences so that regex-specific
characters are treated as literal characters:

  $line =~ s/\Q$fname $lname $addr\E//;

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **

Reply via email to