|
To determine the character set you are running under from perl one could use the return
value of ord() or chr() to test one or more character values. For example:
$is_ascii = "A" eq chr(65);
$is_ebcdic = "A" eq chr(193);
|
|
Also, "\t" is a HORIZONTAL TABULATION character so that:
$is_ascii = ord("\t") == 9;
$is_ebcdic = ord("\t") == 5;
|
|
To distinguish EBCDIC code pages try looking at one or more of the characters that differ
between them. For example:
$is_ebcdic_37 = "\n" eq chr(37);
$is_ebcdic_1047 = "\n" eq chr(21);
|
|
Or better still choose a character that is uniquely encoded in any of the code sets, e.g.:
$is_ascii = ord('[') == 91;
$is_ebcdic_37 = ord('[') == 186;
$is_ebcdic_1047 = ord('[') == 173;
$is_ebcdic_POSIX_BC = ord('[') == 187;
|
|
However, it would be unwise to write tests such as:
$is_ascii = "\r" ne chr(13); # WRONG
$is_ascii = "\n" ne chr(10); # ILL ADVISED
|
|
Obviously the first of these will fail to distinguish most ASCII machines from either a
CCSID 0037, a 1047, or a POSIX-BC EBCDIC machine since "\r" eq chr(13) under all of
those coded character sets. But note too that because "\n" is chr(13) and
"\r" is chr(10) on the MacIntosh (which is an ASCII machine) the second $is_ascii
test will lead to trouble there.
To determine whether or not perl was built under an EBCDIC code page you can use the Config
module like so:
use Config;
$is_ebcdic = $Config{'ebcdic'} eq 'define';
|
|
|