Website hosting service by Active-Venture.com
  

 Back to Index

IDENTIFYING CHARACTER CODE SETS

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';  

 

  

 

Domain name registration - 
Register cheap domain name from $7.95 and enjoy free domain services 
 

Cheap domain name search service -
Domain name services at just
$8.95/year only
 

Register domain name -
Buy domain name registration and cheap domain transfer at low, affordable price.

© 2002-2004 Active-Venture.com Web Site Hosting Service

 

[ Do what you think is interesting, do something that you think is fun and worthwhile, because otherwise you won't do it well anyway.   ]

 

 
 
 

Disclaimer: This documentation is provided only for the benefits of our web hosting customers.
For authoritative source of the documentation, please refer to http://www.perldoc.com