in reply to quotemeta and \% to insert perl code into database

Well, '%' is a non-word character, so quotemeta will escape it. But why are you using quotemeta to prepare for an insert? Why not use place holders, or the 'quote' function from DBI?

Abigail

Replies are listed 'Best First'.
Re: Re: quotemeta %
by macPerl (Beadle) on Mar 12, 2004 at 14:10 UTC
    Abigail,

    As usual, you have given a neat solution - a big thanks !


    (Footnote:
    it still doesn't explain why this issue arises ...
    I should have stated that there are lots of other non-word characters to be inserted in the blob. They are all handled perfectly - i.e. the DBI clears the escapes upon insertion so the next retrieval displays the contents without all escape the characters.

    One to note for the future, I guess.)
      The reason is that quotemeta is used to escape strings for regular expressions and $dbh->quote is used to escape strings for a particular database. For most databases, the only characters that need to be escaped are quotes. Regular expression have many more characters that need to be escaped. My guess is that the database does not unescape some of the escape characters.
      print $dbh->quote("foo\"%!bar"); print quotemeta("foo\"%!bar");
      Prints:
      'foo%"!bar' foo\"\%\!bar