#!/usr/bin/perl
use utf8;
use Encode qw(encode);
# for example, printing to STDOUT
my $perl_string = "IT鐵人賽";
print encode('UTF-8', $perl_string) . "\n"; # in a Linux environment
use URI::Escape;
my $encoded = uri_escape_utf8($perl_string);
print $encoded . "\n";
my $decoded = uri_unescape($encoded);
print $decoded . "\n";
得
IT鐵人賽
IT%E9%90%B5%E4%BA%BA%E8%B3%BD
IT鐵人賽
但是該程式在AIX環境,在執行uri_unescape會報錯如下:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LC_ALL = (unset),
LANG = "zh_CN.IBM-eucCn"
are supported and installed on your system.
perl: warning: Failing back to the standard locale ("C").
從錯誤訊息看,是LC_ALL未設置,是故先執行以下命令再執行上支Perl程式就過關。
export LC_ALL=C
LC_ALL是AIX的環境變數,LC是Locale簡稱,export LC_ALL=C是除去所有本地化的設定。
LC是Locale簡稱,參考:https://www.ibm.com/docs/zh-tw/aix/7.3?topic=locales-understanding-locale-environment-variables