--- Paul Cotter <[EMAIL PROTECTED]> wrote:
> 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

unpack() is your friend. =o)

  print unpack "H*", 'Ab c';

=====
print "Just another Perl Hacker\n"; # edited for readability =o)
=============================================================
Real friends are those whom, when you inconvenience them, are bothered less by it than 
you are. -- me. =o) 
=============================================================
"There are trivial truths and there are great Truths.
 The opposite of a trival truth is obviously false.
 The opposite of a great Truth is also true."  -- Neils Bohr

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Reply via email to