#!/usr/bin/perl use strict; use warnings; use 5.010; my $moji = "Smith"; if ($moji =~ /\w+$/) { print "${moji}は文字です", "\n"; } else { print "${moji}は文字でありません", "\n"; } |
perl shiken1.pl |
Smithは文字です |
#!/usr/bin/perl use strict; use warnings; use 5.010; my $moji = "スミス"; if ($moji =~ /\w+$/) { print "${moji}は文字です", "\n"; } else { print "${moji}は文字でありません", "\n"; } |
スミスは文字でありません |
#!/usr/bin/perl use strict; use warnings; use 5.010; use utf8; my $moji = "スミス"; if ($moji =~ /\w+$/) { print "${moji}は文字です", "\n"; } else { print "${moji}は文字でありません", "\n"; } |
Wide character in print at shiken3.pl line 9. スミスは文字です |
#!/usr/bin/perl use strict; use warnings; use 5.010; use utf8; use Encode; my $moji = "スミス"; my $en_moji = Encode::encode("utf-8", $moji); if ($moji =~ /\w+$/) { print "${en_moji}は文字です", "\n"; } else { print "${en_moji}は文字でありません", "\n"; } |
Wide character in print at shiken12.pl line 11. ã¹ãã¹は文字です |
#!/usr/bin/perl use strict; use warnings; use 5.010; use utf8; use Encode; my $en_moji; my $moji = "スミス"; my $hyoji = "${moji}は文字です"; my $hyoji_not = "${moji}は文字でありません"; $hyoji = Encode::encode("utf-8", $hyoji); $hyoji_not = Encode::encode("utf-8", $hyoji_not); if ($moji =~ /\w+$/) { print $hyoji, "\n"; } else { print $hyoji_not, "\n"; } |
スミスは文字です |