From: "Jeff Pinyan" <[EMAIL PROTECTED]>


> On May 10, Paul Cotter said:
> 
> >What combination of sprintf/pack/upack/asc/hex/xyz.pm etc will allow me
> >to convert a string in to a string hex equivalent. I dare say, in Perl's
> >little quirks there is an arcane subroutine called something like dtcnvx
> >that does just what I want...
> 
> Sadly, the oct() and hex() functions are poorly named; they should be
> from_oct() and from_hex().  You want to use sprintf().
> 
>   $as_hex = sprintf "%x", $num;
>   $as_hex = sprintf "%#x", $num;  # adds a leading "0x"

Unfortunately this does not work if we have $str rather then $num if you see what I 
mean.

printf ( "%#x" , 'abc' ) #gives  Argument "abc" isn't numeric in printf at...

If I can just re-iterate my original request:

print dtcnvx('Ab c')     # gives   41622063

However, it is interestingto note that the following code:

 print my $s = sprintf ("%#x \n" , 'abc');
 printf ("%#x \n" , 'abc');

Gives the following output:

0
Argument "abc" isn't numeric in printf at diet.pl line 397.
0

Regards - Paul Cotter


Reply via email to