On 12-07-12 02:08 PM, Manfred Lotz wrote:
The following code works fine. However, I like to know how to retrieve
the UTF-8 hex representation of $uchar which is x'e0a487'. This is the
internal representation in Perl, so it should be possible to print it
out. Is there any function or module I could use to do this?

Well, this is the hard way:

#!/usr/bin/env perl

use 5.010;
use strict;
use warnings;

use utf8;

binmode STDOUT, ':utf8';

# this is code point U+0907, its name is
# DEVANAGARI LETTER I
# its utf8 hex representation is x'e0a487'
my $uchar = 'इ';

# this is 1
my $len = length $uchar;

say "Length of $uchar is $len";

my $hex = sprintf '%04x', ord($uchar);
say "Unicode for $uchar is U+$hex";

my $bytes;
open my $fh, '<', \$uchar or die $!;
{
  local $/;
  $bytes = <$fh>;
}
close $fh;
print "Bytes of $uchar are 0x";
printf '%02x', ord( $_ ) for split //, $bytes;
say '';


--
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

        _Perl links_
official site   : http://www.perl.org/
beginners' help : http://learn.perl.org/faq/beginners.html
advance help    : http://perlmonks.org/
documentation   : http://perldoc.perl.org/
news            : http://perlsphere.net/
repository      : http://www.cpan.org/
blog            : http://blogs.perl.org/
regional groups : http://www.pm.org/



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to