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

How do I convert a string "D'ith" to "D\'ith". Thanks.

Replies are listed 'Best First'.
Re: Escaping a string
by Zaxo (Archbishop) on Mar 13, 2003 at 20:42 UTC

    quotemeta. The command line will be tough to test this on, since the shell will interfere.

    After Compline,
    Zaxo

      I'm doing from within perl - I define and declare the string in perl, and send the result to mysql. Plus, how do I convert "D\'ith" to "D'ith". Thank you.

        If you are using DBI to access MySQL then something like this may be better.

        use DBI; my $dbh=DBI->connect('DSN info here'); my $string="D'ith"; my $val_to_put_in_mysql=$dbh->quote($string);

        Or if you are using placeholders in your query then DBI will do the quote on insert for you. Either way DBI will fetch it back as D'ith for you.

        From the DBI docs:
        use DBI; $quoted_string = $dbh->quote($string);
        If my understanding of black magic is correct that should take care of your quoting on the way into the DB. You should be able to select, etc. at will and have it come back out of the DB in its original (unescaped) form.
A reply falls below the community's threshold of quality. You may see it by logging in.