Thanks Corion.

Sorry, the view part is using the inbuilt "alert" function of Javascript. This is what I see of the json string from perl passed to Javascript using "alert":
{ "hex_code":"\\xa5" }
When I display this in an html input field, it displays:
\xa5
After much googling with the right keywords, I found a solution by passing the value "\\xa5" (which originates from perl) to the function below:
//https://stackoverflow.com/questions/4209104/decoding-hex-string-in-j +avascript String.prototype.decodeEscapeSequence = function() { return this.replace(/\\x([0-9A-Fa-f]{4})/g, function() { return String.fromCharCode(parseInt(arguments[1], 16)); }); };
I think it's somewhat similar to your perl code below:
sub unescape { my( $str ) = @_; $str =~ s!\\x\{([0-9a-f]{4})\}!chr(hex $1)!ge; $str };
I am confused because when I have a variable set to a hex value in Javascript like this:
var hex_code = '\xa5';
That gets displayed correctly in the input field as a symbol.

So I thought since "\\xa5" is what I see with Javascript's alert, if I remove the first backslash, it would work. It doesn't whether I remove the first backslash or not. I needed to unescape with the Javascript function found in stackoverflow.

In reply to Re^6: Print unicode strings to pdf by Anonymous Monk
in thread Print unicode strings to pdf by Anonymous Monk

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.