#!/usr/bin/pe
1. my $smiley = "\xE2\x98\xBA";
2. print $smiley . "\n";
3. _utf8_on($smiley);
4. print $smiley . "\n";
####
U+00E2 LATIN SMALL LETTER A WITH CIRCUMFLEX
U+0098 START OF STRING
U+00BA MASCULINE ORDINAL INDICATOR
####
U+263A WHITE SMILING FACE
####
# Explicit encode()
use Encode qw(encode);
print encode("UTF-8", $smiley):
# Set the filehandle to the encoding UTF-8
binmode STDOUT, ":encoding(UTF-8)";
print $smiley;
# Set the filehandle to :utf8, a shortcut syntax because you need it so often
binmode STDOUT, ":utf8";
print $smiley
####
use utf8;
use Socket qw(inet_aton);
use Encode qw(encode);
my $text_string = "Héllø wõrld!";
my $binary_string = inet_aton("127.0.0.1");
my $data_to_send;
# Now, we need to send both in one go!
# But we can't do that directly, because $text_string needs to be encoded first.
# How shall we encode it?
# As UTF-8?
$data_to_send = encode("UTF-8", $text_string) . $binary_string;
print $data_to_send;
# As ISO-8859-1?
$data_to_send = encode("ISO-8859-1", $text_string) . $binary_string;
print $data_to_send;
# As KOI8-R?
$data_to_send = encode("KOI8-R", $text_string) . $binary_string;
print $data_to_send;
# Oops, these characters don't exist in KOI8-R, so Perl used question marks. Heehee :)
####
my Buf $byte_string;
my Str $text_string;