Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks, can somebody tell me how do i convert a utf-8 string to hex format in perl? i am a bit new to all these.

Replies are listed 'Best First'.
Re: Hex conversion
by rupesh (Hermit) on Aug 13, 2003 at 07:55 UTC
    Use Unicode::String They have seperate functions to perform variuos tasks. Hope it helps.

    we're born with our eyes closed and our mouths wide open, and we spend our entire life trying to rectify that mistake of nature. - anonymous.
Re: Hex conversion
by bm (Hermit) on Aug 13, 2003 at 09:33 UTC
    When working with utf-8 data in Perl, I recommend Perl version 5.8.1 and the Encode modules.


    --
    bm

Re: Hex conversion (unpack"H*")
by tye (Sage) on Aug 13, 2003 at 20:23 UTC

    Most interpretations I come up with for "hex format" depend on the bytes of the string not the characters so whether your string is encode in UTF-8 or not probably has no bearing. However, whether Perl thinks your string is UTF-8 encoded or not might have a bearing, depending what you do with it.

    But some quick testing shows that:

    my $hex= unpack "H*", $string;
    works fine for all strings (whether in UTF-8 or not and whether or not Perl thinks they are UTF-8 or not) under Perl 5.6. I doubt that particular case changed in Perl 5.8 but I haven't had a reason to install that yet so I can't easily test.

                    - tye