Perl: Hangul Processing - Basic (Korean Letters) - by Eun Bae Kim (07/19/2019)
 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
  
use strict;
use Encode;

# This Script was saved in UTF-8.
# cp944(ms949) = Basic encoding method in Windows. Extension of EUC-KR.
# When you save a text in ANSI, the text will be encoded in cp944.
# One Korean Letter takes 2 bytes in cp949 and 3 bytes in UTF-8.

my $s1="가나다라마바사";
print "Line01: ".$s1."\n";
print "Line02: ".length($s1)."\n";

my $s2 = encode("cp949", decode("UTF-8", $s1));
print "Line03: ".$s2."\n";
print "Line04: ".length($s2)."\n";

$s1=~/마/;
print "Line05: ".encode("cp949", decode("UTF-8", $`))."\n";
print "Line06: ".encode("cp949", decode("UTF-8", $&))."\n";
print "Line07: ".encode("cp949", decode("UTF-8", $'))."\n";