On Aug 17, 11:48 am, [EMAIL PROTECTED] (Gunnar Hjalmarsson) wrote:
> dinesh wrote:
> > I have a requirement for passing a hex value like this to a function.
>
> > Example code:
> > my $ipmbAddress = getIpmbAddress(...); ## returns 82
>
> > getDeviceID($ip, $ipmbAddress);
>
> > Here in the above code, the getDeviceID() fucntion will accept only
> > 0x82 (hex number). How to convert the number 82 to 0x82 (Note that
> > this should not be as string)
>
> I think it must be a string, or else Perl will convert it to decimal
> whether you like it or not...
>
> my $num = 0x82;
> print "$num\n"; # prints 130
>
> So if the function expects a hex value, you'd better pass it as a string.
To put it another way what _precisely_ does getDeviceID expect?
There's no such thing as "a hex number" or a "decimal number". There
are just numbers and representations of them.
my $num = 0x82;
or
my $num = 130;
These will set $num to the same value - which is just a number (well
an integer actually). If you want to claim it has any base then it's
base-2 because that's what the hardware uses. But really it's just an
number.
As soon as I use $num in a string context then $num will become a
"dualvar" with the string value '130' in addition to the numeric
value.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/