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

Hello,

Trying to replace any ' (single quotes) in a string with '

tried $dsname =~ s/'/'/g;

but that obviously didn't work.

Any quick tips?

Replies are listed 'Best First'.
Re: Quotes to 'HTML' Quotes...
by Trimbach (Curate) on Mar 16, 2004 at 12:54 UTC
    Or better yet:
    use HTML::Entities qw(encode_entities_numeric); $dsname = encode_entities_numeric( $dsname );
    Easy, to the point, and fixes a lot more than just single quotes. :-)

    Gary Blackburn
    Trained Killer

      * Your a star *
Re: Quotes to 'HTML' Quotes...
by matija (Priest) on Mar 16, 2004 at 12:48 UTC
    $a="'Obviously?'"; $a=~s/\'/'/g; print $a."\n";
    # /tmp/q
    'Obviously?'

    Update:I just checked: $a=~s/'/'/g; (i.e. without escaping the quote) works, too.

Re: Quotes to 'HTML' Quotes...
by Old_Gray_Bear (Bishop) on Mar 16, 2004 at 12:46 UTC
    Shouldn't it be
    $dsname =~ /\'/'/g;
    with the bip escaped?

    ----
    I Go Back to Sleep, Now.

    OGB

      What makes you think escaping the quote matters?

      Abigail