Dharshana Eswaran wrote:
> Hi all,

Hello,

> I am working on the code below....
> 
> use strict;
> use warnings;
> 
> my $hex = "43";
> 
> my $binary = unpack 'B*', pack 'H*', $hex;
> 
> print "$binary\n\n";
> 
> my @fields = unpack 'A2A2A4', $binary;
> 
> my $i;
> printf "%-4s => %s\n", $fields[$i++], $_ foreach qw/Ext TypeofNumber
> NumberingPlan/;

Do you need to do this with strings or should you be using numbers instead?

> **OUTPUT**
> 
> 01000011
> 
> 01 => Ext
> 00 => TypeofNumber
> 0011 => NumberingPlan
> 
> But, now i have a hash(associative array),
> 
> %TypeofNumber  = ( 00 => Integer, 01 => Floating, 10 => Char, 11 => Double
> );

Perl interprets numbers beginning with 0 as octal and the other numbers as
decimal so 00 is the number 0, 01 is the number 1, 10 is the number ten and 11
is the number eleven.  Since you are using strings you have to quote the
digits or they will be interpreted as numbers, and you have to quote the other
strings because barewords are not allowed with the strict pragma, so:

my %TypeofNumber = (
    '00' => 'Integer',
    '01' => 'Floating',
    '10' => 'Char',
    '11' => 'Double',
    );

Or:

my %TypeofNumber = qw( 00 Integer 01 Floating 10 Char 11 Double );



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to