#! /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;
####
s/((\\+)x\{([0-9a-f]{2,})\})/
(length($2) % 2) ? substr($2, 1) . chr hex $3 : $1/ger;
##
##
#! /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;