[Novalug] detecting system character sets

donjr djr1952@hotpop.com
Fri May 11 10:30:52 EDT 2007


On Fri, 2007-05-11 at 08:49 -0400, Bonnie Dalzell wrote:
> Is there a simple way to have the system tell you what character set
> it uses as default? 
> 
> A command line command for example which I could have a perl program run
> using its exe command?
> 
> Perl has built in commands to let you find out which OS you are
> running.

Under *NIX the command is:
  $  locale

See: "man locale" for details.

It will output something to the following effect:
 LANG=en_US.UTF-8
 LANGUAGE=en
 LC_CTYPE="en_US.UTF-8"
 LC_NUMERIC="en_US.UTF-8"
 LC_TIME="en_US.UTF-8"
 LC_COLLATE="en_US.UTF-8"
 LC_MONETARY="en_US.UTF-8"
 LC_MESSAGES="en_US.UTF-8"
 LC_PAPER="en_US.UTF-8"
 LC_NAME="en_US.UTF-8"
 LC_ADDRESS="en_US.UTF-8"
 LC_TELEPHONE="en_US.UTF-8"
 LC_MEASUREMENT="en_US.UTF-8"
 LC_IDENTIFICATION="en_US.UTF-8"
 LC_ALL=


The vars LANG and LANGUAGE are by default part of your environment as
returned by the 'env' command. The others can be added if you really
need to customize things.

> I have a program I am working on which accesses a database created under
> DOS. Although the first 127 ascii characters are constant between most
> operating systems the next 127 have varied assignments depending on which 
> OS they are and which character set they use. There are euro characters
> in this database and it is pretty simple for me to set up various
> translation to other character set routines - I have one that takes the
> euro characters into their nearest low ascii equivalents and one that
> properly translates them into their html representations but i would
> like to do one to allow them to actually display correctly under
> UTF-8. But I want it to be smart - that is to find out if the current
> system is running UTF-8 before putting things through the translation.

You might also want to take a look at:
  man 7 locale

This describes the C language include file "#include <locale.h>"

I do believe that Perl has something on the order of this as part of
it's own multi-language support feature(s).


--  
-- 
 Don E. Groves, Jr. 

$ /usr/games/fortune : 
You have an unusual understanding of the problems of human
relationships.



More information about the Novalug mailing list