It wouldn't :) Data::JavaScript may help
use Data::JavaScript; print 'alert("', Data::JavaScript::__quotemeta(qq,ab\x22q\x27uo\x27te\x22cd,), '");',"\n"; __END__ alert("ab\"q'uo'te\"cd");
To get something you can inline
perl -MData::JavaScript -MData::Dumper -e ' $Data::Dumper::Deparse=1; +die Dumper \&Data::JavaScript::__quotemeta '
which you can use like
$VAR1 = sub { package Data::JavaScript; use strict 'refs'; local $_ = shift @_; if ($OPT{'JS'} >= 1.3 and &Encode::is_utf8($_)) { s/([\x{0080}-\x{fffd}]+)/sprintf '\\u%0*v4X', '\\u', $ +1;/eg; } { use bytes; s/((?:[^ \x21-\x7E]|(?:\\(?!u)))+)/sprintf '\\x%0*v2X' +, '\\x', $1;/eg; } s/\\x09/\\t/g; s/\\x0A/\\n/g; s/\\x0D/\\r/g; s/"/\\"/g; s/\\x5C/\\\\/g; s[</script>][\\x3C\\x2Fscript\\x3E]g; return $_; }; print 'alert("', $VAR1->(qq,ab\x22q\x27uo\x27te\x22cd,), '");',"\n"; __END__ alert("ab\"q'uo'te\"cd");

In reply to Re^2: Quote Escape by Anonymous Monk
in thread Quote Escape by pileofrogs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.