in reply to Re: Escaping Apostrophe
in thread Escaping Apostrophe

Not trying to reinvent the wheel. But this is the code we have in just one of many places, using abstract or anything else will require a lot of changes through the code. All I need is a quick and dirty solution with what I have.

Replies are listed 'Best First'.
Re^3: Escaping Apostrophe (updated)
by AnomalousMonk (Archbishop) on Oct 20, 2017 at 16:08 UTC

    Quick, dirty — and, per other replies, kinda crazy (and also untested):

    my ($row_sub_i_esc_sq = $row[$idx]) =~ s{ ' }{\\}xmsg; $updstmt .= $hdr[$idx]." = '". $row_sub_i_esc_sq ."' \r\n";
    And BTW: It looks like you're dealing with single-quote characters, not apostrophes.

    Update: Oops... Meant to write  s{ (?= ') }{\\}xmsg; and the substitute-on-assignment expression is also wrong, so finally (I think):

    (my $row_sub_i_esc_sq = $row[$idx]) =~ s{ (?= ') }{\\}xmsg; $updstmt .= $hdr[$idx]." = '". $row_sub_i_esc_sq ."' \r\n";
    Thanks choroba. Of course, that's what always happens when I post untested stuff.


    Give a man a fish:  <%-{-{-{-<