Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

LANG setting and code pages

by adolpht (Novice)
on Oct 12, 2004 at 13:56 UTC ( [id://398494]=perlquestion: print w/replies, xml ) Need Help??

adolpht has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I'm running some DBI code on a Red Hat server and failing to correctly display umlauts (). Initially I thought it was a NLS_LANG problem, but found it to be what I'd call a code page problem if I was running on a Windows platform. This code prints gubble-de-gook (where the umlaurts should be): #!/usr/bin/perl print "Umlaut : \n"; But if I unset LANG it runs... *but* then I can't then use vi to edit the umlauts. Can some clever monk please explain how LANG (and anthing I've missed) affect the translation of what you type and what get displayed and why vi doesn't use the same mechanism. Cheers Tony

Replies are listed 'Best First'.
Re: LANG setting and code pages
by dave_the_m (Monsignor) on Oct 12, 2004 at 14:16 UTC
    At a guess I'd say that your LANG setting includes a '.uft8' at the end, and that you're running perl-5.8.0. In that case, perl unfortunately concludes that all its input is utf-8 encoded, and characters in the range 128-255 get generally screwed up. If this is the case, either upgrade to a newer perl release, or remove the .utf8 suffix from $LANG.

    Dave.

Re: LANG setting and code pages
by iburrell (Chaplain) on Oct 12, 2004 at 22:25 UTC
    What version of Red Hat? What is your LANG env variable? What encoding are you using for your terminal? Your database?

    You need to match the encoding of the terminal, LANG environment, and database if you want to see characters properly. Or do the character set translation. Inside the Oracle client is a common place (that is what NLS_LANG controls).

    LANG signals the locale for formatting dates and stuff, and also the character set. For example en_US.UTF-8 is UTF-8.

    Perl should not do any character set translation by default. Some older 5.8 versions of Perl had problems with opening stdout as utf8 when .UTF-8 was on LANG. This caused module install problems. Newer versions fixed this problem but some Red Hat releases shipped with those versions of Perl, and put UTF-8 on the locale. Red Hat 9 is the one that caused the most trouble.

      Thanks for the replies, Red Hat : Red Hat Enterprise Linux ES release 3 (Taroon Update 1) LANG=en_US.UTF-8 Putty Terminal encoding UTF-8 I have cut Oracle out completely, I have the simplest possible to test the problem, i.e. print "Umlaut \n"; If I leave LANG set, I can edit my script and type in vi, but the output is messed up when I run it, if I unset LANG, the script output looks good, but I can't use vi to edit the umlauts. What setting(s) do I need to be able to print a from perl *and* be able to edit the script and change it? Cheers, Tony
        Like I said earlier, remove the .utf8 suffix from $LANG, ie in you case, set it to en_US.

        Dave.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://398494]
Approved by ysth
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-22 05:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found