note
choroba
Nice and easy! But, it's prone to Unicode injection:
<c>#! /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;
</c><P>
<B>Update:</B> Possibly fixable by
<c>
s/((\\+)x\{([0-9a-f]{2,})\})/
(length($2) % 2) ? substr($2, 1) . chr hex $3 : $1/ger;
</c><P>
Verified by
<readmore><c>
#! /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;
</c></readmore><P>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-832495">
<c>map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]</c>
</div></div><!-- Wiki2Monks {"version":1.16} -->
11115241
11115297