Data::Translate - Translate string data between a few patterns (binary,decimal,ascii,hex)
use Data::Translate; $data=new Translate; # Example, translating from hex to Ascii # $s receives the status of the operation @hh=qw(64 65 6e 61 6f); ($s,@ha)=$data->h2a(@hh); print join('',@ha),"\n"; ## will output "denao"
This module is intended to translate data between a few patterns. Basicly, it is a ease mode to pack/unpack stuff. Imagine, you have a script that treats hex data, and you need to see the values, in other format, like decimal, binary or even ascii. This module implements a symplistic way to Translate values smoothly returning the status of operation and values always on a string. You may translate at this point: - ascii to binary - ascii to decimal - ascii to hex - decimal to ascii - decimal to binary - decimal to hex - binary to ascii - binary to decimal - binary to hex - hex to binary - hex to decimal - hex to ascii Please, head to test.pl for additional examples. The functions you'll call, are defined as the first byte of each data type. If you want to translate from binary to hex, you'll use the function b2h, and if you want to translate from ascii to decimal, you'll use a2d, and so on.
->new
Creates a new instance of Translation. eg.: $data=new Translate;
->a2b
($s,$bin)=$data->a2b($str);
->a2d
($s,@dec)=$data->a2d($str);
->a2h
($s,$hh)=$data->a2h($str);
->b2a
($s,$asc)=$data->b2a($bin);
->b2d
@t=unpack("A8" x (length($bin)/8),$bin); foreach $binary (@t) { ($s,$d)=$data->b2d($binary); print "--> $d\n"; }
->b2h
foreach $binary (@t) { ($s,$hx)=$data->b2h($binary); print "--> $hx\n"; }
->d2a
->d2b
->d2h
->h2a
->h2b
($s,@hd)=$data->h2d(@hh);
->h2d
($s,@hb)=$data->h2b(@hh);
perl(1)
To install Data::Translate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Translate
CPAN shell
perl -MCPAN -e shell install Data::Translate
For more information on module installation, please visit the detailed CPAN module installation guide.