Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Nice and easy! But, it's prone to Unicode injection:
#! /usr/bin/perl use warnings; use strict; use Data::Dumper; my %mydatatoshow = ( "\N{GREEK SMALL LETTER ALPHA}" => "\\\N{GREEK SMALL LETTER BETA}", '\\x{3b1}' => '\\\\x{3b2}', ); binmode STDERR, ':encoding(UTF-8)'; print STDERR Dumper(\%mydatatoshow); print STDERR Dumper(\%mydatatoshow) =~ s/\\x\{([0-9a-f]{2,})\}/chr(hex +($1))/ger;

Update: Possibly fixable by

s/((\\+)x\{([0-9a-f]{2,})\})/ (length($2) % 2) ? substr($2, 1) . chr hex $3 : $1/ger;

Verified by

#! /usr/bin/perl use warnings; use strict; use Data::Dumper; my %datatoshow = ( "\N{GREEK SMALL LETTER ALPHA}" => "\\\N{GREEK SMALL LETTER BETA}", '\\x{3b1}' => '\\\\x{3b2}', ); binmode STDERR, ':encoding(UTF-8)'; print STDERR Dumper(\%datatoshow); print STDERR Dumper(\%datatoshow) =~ s/((\\+)x\{([0-9a-f]{2,})\})/ (length($2) % 2) ? substr($2, 1) . chr hex $3 : $1/ger; use Test::More tests => 3; my $dumper_orig = Dumper(\%datatoshow); my $dumper_leszekdubiel = $dumper_orig =~ s/\\x\{([0-9a-f]{2,})\}/chr(hex($1))/ger; my $dumper_choroba = $dumper_orig =~ s/((\\+)x\{([0-9a-f]{2,})\})/ (length($2) % 2) ? substr($2, 1) . chr hex $3 +: $1/ger; my $VAR1; eval $dumper_orig; is_deeply $VAR1, \%datatoshow; eval $dumper_leszekdubiel; is_deeply $VAR1, \%datatoshow; eval $dumper_choroba; is_deeply $VAR1, \%datatoshow;

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

In reply to Re^2: Convert JSON to Perl and back with unicode by choroba
in thread Convert JSON to Perl and back with unicode by bliako

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-24 07:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found