in reply to Strip bad characters from a string

You want tr.
$_ = <<STOP; 'foo' is in single quotes, "bar" is in double quotes, and there are carriage returns between STOP tr/'"\n//d; print;

Replies are listed 'Best First'.
RE: Strip bad characters from a string
by AF_INET (Initiate) on Apr 11, 2000 at 21:45 UTC
    Instead of just stripping them, how do I make a ' into a \' and " into a \". I tried using your example and adapting it but the result was \\\\\\\\\\\\\\\\\\\\\\\\\\\\' because it keeps looping just looking for the single character. Any ideas appreciated. Ian.
      Try
      s#(['"])#\\$1#g;
      Result (using the same string that I used the first time):
      \'foo\' is in single quotes, \"bar\" is in double quotes, and there are carriage returns between