develooper Front page | perl.i18n | Postings from July 2003

Extending the scope of a PERLIO layer across packages

Krout, Frank
July 16, 2003 08:51
Extending the scope of a PERLIO layer across packages
Message ID:

I'm trying to support a legacy multilingual website that has been upgraded
to perl58 and now using PERLIO to properly encode html output. (STDOUT is
mapped via binmode)

In an effort to only change a few globally included packages, rather than
all the scripts or all the content, I like to find a way to associate a
charset (other than utf8) dynamically to all FILE IO when building web pages
from encoded templates.

The following works fine within the scope of the including package:

use open IN => ":encoding(shiftjis)";
open FILE,"cp_email_JPJA_sendemail.txt.sjis";

or something like

open (FILE,"<:utf8","cp_email_JPJA_sendemail.txt.utf8");

but I'd like to do something like use open IN => ":encoding(shiftjis)"; in a
module that all application scripts and cgi's would include.

I've tried perllocale without success to at least produce UTF8 mapped file
handles unilaterally:

use  POSIX  qw (locale_h);
use locale;
$ENV{LC_ALL} = $ENV{LANG} = 'UTF-8';

From perlunicode.html:
Usually locale settings and Unicode do not affect each other, but there are
a couple of exceptions: 
*	If your locale environment variables (LANGUAGE, LC_ALL, LC_CTYPE,
LANG) contain the strings 'UTF-8' or 'UTF8' (case-insensitive matching), the
default encodings of your STDIN, STDOUT, and STDERR, and of any subsequent
file open, are considered to be UTF-8. 
*	Perl tries really hard to work both with Unicode and the old
byte-oriented world. Most often this is nice, but sometimes Perl's
straddling of the proverbial fence causes problems. 
As I said I can't seem to get this tweaked right to work. At least one could
standardize on utf8 content and then output in whatever encoding was

Any thoughts would be greatly appreciated.

Here are system particulars:

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
    osname=solaris, osvers=2.6, archname=sun4-solaris-thread-multi
    uname='sunos seal 5.6 generic_105181-29 sun4u sparc sunw,ultra-5_10 '
    config_args='-Dcc=gcc -Dinstallprefix=/usr/local -Dprefix=/usr/local
-Dusethreads -des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='gcc', ccflags ='-D_REENTRANT -I/usr/local/include
    cppflags='-D_REENTRANT -I/usr/local/include'
    ccversion='', gccversion='2.8.1', gccosandvers='solaris2.7'
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib '
    libpth=/usr/local/lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -ldl -lm -lposix4 -lpthread -lc
    perllibs=-lsocket -lnsl -ldl -lm -lposix4 -lpthread -lc
    libc=/lib/, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'
Characteristics of this binary (from libperl): 
  Built under solaris
  Compiled at May 16 2003 11:49:23


Frank K. Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About