On Wed, 14 Aug 2002, Jacobson, Karl wrote:

> I am trying simply to do a search and replace and have identified the string
> that I want to replace with another.
>
> $_ holds the string to be manipulated
> $was holds the search string (split from an input file)
> $is holds the replacement string (also split from an input file)
>
> s/$was/$is/; doesn't work and I expected that it would.  What is missing?
>

>From the information you provided, nothing appears wrong.

Additional useful information:

1. When you split the $was and $is variables from an input line,
   did you chomp() the line first to make sure that the variables
   didn't end up containing a trailing \n character. What about
   trailing spaces?

2. Does $was or $is contain any regex metacharacter or / character?
   If yes (or maybe) you need to change your regex to:

      s/\Q$was\E/\Q$is\E/;

For debugging purposes, I suggest that you do:

print SDTERR "previous value: $_\n";
print STDERR "length(\$was) = ",length($was),"\n";
print STDERR "\$was: $was\n";
print STDERR "length(\$is) = ",length($is),"\n";
print STDERR "\$is: $is\n";
if (s/$was/$is/) {
    if ($was eq $is) {
       print STDERR "\$was eq \$is\n";
    }
    else {
      print STDERR "new value: $_\n";
   }
}
else {
  print STDERR "target $was was not found in $_\n";
}

Does the output produced show you where the problem is?

**** [EMAIL PROTECTED] <Carl Jolley>
**** All opinions are my own and not necessarily those of my employer ****

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to