perl-unicode

Re: getBytes in perl ?!?

2004-12-02 06:30:08
PerlDiscuss - Perl Newsgroups and mailing lists wrote:

Do you know if there is in Perl the function "getBytes" in Java ?
I would like to convert a "string" to bytes in perl.

the idea could be :
$mystring="Hello EveryBody. How are you ?";
$mybytes = getBytes($mystring);
$mybytes="0x3C3F786D6C2076657273696F6E3D22312E"; #something like

Do you mean something like this:

perl -le '$s="Smile \x{263A}"; print join("-",unpack("U*",$s))'

Unpack("U*"...) understands Unicode, and returns one number for
each character (not byte) (i.e. one large number for the smiling
face character).

Or do you want one number for each utf8-encoded byte (I.e. three
hexpairs for the smiling face character).

perl -le '$s="Smile \x{263A}"; print unpack("H*",$s)'



Perl Version : 5.6.1
Apparently, I do not have the "Encode.pm" in my libraries.


--
Paul Bijnens, Xplanation                            Tel  +32 16 397.511
Technologielaan 21 bus 2, B-3001 Leuven, BELGIUM    Fax  +32 16 397.512
http://www.xplanation.com/          email:  
Paul(_dot_)Bijnens(_at_)xplanation(_dot_)com
***********************************************************************
* I think I've got the hang of it now:  exit, ^D, ^C, ^\, ^Z, ^Q, F6, *
* quit,  ZZ, :q, :q!,  M-Z, ^X^C,  logoff, logout, close, bye,  /bye, *
* stop, end, F3, ~., ^]c, +++ ATH, disconnect, halt,  abort,  hangup, *
* PF4, F20, ^X^X, :D::D, KJOB, F14-f-e, F8-e,  kill -1 $$,  shutdown, *
* kill -9 1,  Alt-F4,  Ctrl-Alt-Del,  AltGr-NumLock,  Stop-A,  ...    *
* ...  "Are you sure?"  ...   YES   ...   Phew ...   I'm out          *
***********************************************************************


<Prev in Thread] Current Thread [Next in Thread>
  • getBytes in perl ?!?, PerlDiscuss - Perl Newsgroups and mailing lists
    • Re: getBytes in perl ?!?, Paul Bijnens <=