in reply to Re: Re: Escaping a string
in thread Escaping a string

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.

Replies are listed 'Best First'.
Re: : Re: Escaping a string
by Anonymous Monk on Mar 13, 2003 at 21:23 UTC
    THanks, out of interest, how would I escape using a regex.

      Frankly you got a bunch of valid answers here (zaxo for instance answered your question, but you didnt seem to grok it.) Around here we usually like to see people make some effort in their questions. Some kind of sign that we the respondants arent putting more effort into things than the questioner. Anyway,

      s/(\\\\|\\')|'/$1 ? $1 : "\\'"/ge;

      will do something like what you want. Its so confusing and strange looking because it doesnt screw up preescaped data (assuming that \\ is really a \). Theres probably cleaner nicer looking ways to do it to, but this works and came off the top of my head.

      Oh and please dont ask what/how it works. Read perlre like the rest of us did.


      ---
      demerphq


        Quoth the Annonymous Monk (emphasis added):
        THanks, out of interest, how would I escape using a regex.
        This wording tells me that he was satisfied with the original answer(s), but "for leaning's sake" wondered if there was another way. Granted, once the problem is solved you have more time to futz with it and probably should, but there you go.

        thor