Results 1 to 5 of 5
  1. #1
    Join Date
    May 2002
    Posts
    28

    Unanswered: Single Quote replacement!!!

    Hi,

    I want to insert a value from a variable into database...
    But the value contains a ' (single quote) which cannot be inserted into the database...
    I need to escape it with another '.....
    Like for eg
    variable x="O'Brien" which has to be "O''Brien".
    How can i achieve this in perl?????

    Thanks in advance...

  2. #2
    Join Date
    May 2002
    Posts
    28

    got the answer

    $x = O'Brien;
    $x =~ s/'/''/g;

  3. #3
    Join Date
    Aug 2003
    Posts
    11
    Its called a regular expression. They are hard to learn but once u got em they are AMAZINGLY HELPFUL. Look up on google for a regx tutorial, there are tons.

  4. #4
    Join Date
    May 2002
    Posts
    28

    Thanks

    Thanks for the extended help...

    Regards
    Deb

  5. #5
    Join Date
    Aug 2003
    Posts
    3
    That works, but a far more robust solution would be to
    Code:
    use DBI;
    and then either pass non-numeric variables through
    Code:
    $dbh->quote()
    or bind the params which will handle escaping for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •