Try this:
use strict; use warnings; my $line = '48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21'; my @cbytes = split / /, $line; my $retString; foreach my $byte (@cbytes) { my $hex = '0x'.$byte; my $value = eval $hex; my $char = chr $value; $retString .= $char; } print $retString;
The trick is that perl will evaluate a literal number as hex if you prefix it with '0x', you then need to use eval to force perl to re-evalute it as a number instead of a string. From there is is just a matter of using chr (see perlfunc) to turn that number into a 1 char string.
In reply to Re: Basic transformations
by chrestomanci
in thread Basic transformations
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |