From: volantecho on
Hi,

Code :
$string = "0041";
$hexcode = '\x{'.$string.'}';
$hexcode2 = "\x{0041}";

use Data::Hexdumper;
$hexcode = hexdump(data=>$hexcode);

print $hexcode; # show \x{0041}
print $hexcode2; # show A

What can i do to make $hexcode shown as $hexcode2?
Thanks for every comments

From: Anno Siegel on
<volantecho(a)gmail.com> wrote in comp.lang.perl.misc:
> Hi,
>
> Code :
> $string = "0041";
> $hexcode = '\x{'.$string.'}';
> $hexcode2 = "\x{0041}";
>
> use Data::Hexdumper;
> $hexcode = hexdump(data=>$hexcode);
>
> print $hexcode; # show \x{0041}
> print $hexcode2; # show A
>
> What can i do to make $hexcode shown as $hexcode2?

I'm not sure what "make $hexcode shown as ..." means. You can let Perl
evaluate the string in $hexcode as a literal:

print eval "qq($hexcode)", "\n";

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
From: Brian McCauley on

Anno Siegel wrote:
> <volantecho(a)gmail.com> wrote in comp.lang.perl.misc:
> > Hi,
> >
> > Code :
> > $string = "0041";
> > $hexcode = '\x{'.$string.'}';
> > $hexcode2 = "\x{0041}";
> >
> > use Data::Hexdumper;
> > $hexcode = hexdump(data=>$hexcode);
> >
> > print $hexcode; # show \x{0041}
> > print $hexcode2; # show A
> >
> > What can i do to make $hexcode shown as $hexcode2?
>
> I'm not sure what "make $hexcode shown as ..." means. You can let Perl
> evaluate the string in $hexcode as a literal:
>
> print eval "qq($hexcode)", "\n";

Be aware that if the OP's intent is to allow \x{} escapes in data files
then using eval allows interpolation with $ and @ and also allow the
execution of arbitrary malicious code.

From: volantecho on
cool! i use eval then solve the problem!!
thanks a lot for you guys help :)

From: Anno Siegel on
<volantecho(a)gmail.com> wrote in comp.lang.perl.misc:
> cool! i use eval then solve the problem!!
> thanks a lot for you guys help :)

You have seen Sinan's warning, haven't you?

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.