in reply to Basic transformations
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Basic transformations
by JavaFan (Canon) on Nov 29, 2010 at 14:17 UTC | |
by chrestomanci (Priest) on Nov 30, 2010 at 12:36 UTC | |
by JavaFan (Canon) on Nov 30, 2010 at 14:23 UTC |