http://www.perlmonks.org?node_id=119303

eubios has asked for the wisdom of the Perl Monks concerning the following question:

In other words, how do I convert single quotes into escaped single quotes?

Replies are listed 'Best First'.
Re: How do I convert ( ' ) into something Prolog's name/2 can handle, e.g. ( \' )?
by MrNobo1024 (Hermit) on Oct 17, 2001 at 07:56 UTC
    Just use a substitution regex:
    $str =~ s|'|\\'|g;
Re: How do I convert ( ' ) into something Prolog's name/2 can handle, e.g. ( \' )?
by Anonymous Monk on Oct 18, 2001 at 03:25 UTC
    I have no answer actually but the same problem. I want to pass a string coming from an html form through a perl script to prolog for parsing, but when single quotes are met the processing is stopped. An expression like "John's hat" cannot be processed.

    Simple substitutions like the one above do not work as expected. In fact the above regex makes the script non functioning and an error message pops up saying "Form contains no data". There must be a way but certainly not a very much obvious, since I have tried already several tricks and combinations to achieve it.

    Temporarily I replace single quotes with backticks. But this does not cover all possible cases for natural language processing. The question of eubios remains open.

    Originally posted as a Categorized Answer.