[kansaipm] use encodingの使い方

片松 祐司 katama2-ml at osk.toppan.co.jp
Tue May 13 09:32:03 CDT 2003


片松@凸版 です

お久しぶりです

perl5.8を用いて
入力ファイル       euc-jp
スクリプトファイル euc-jp
出力 iso-2022-jp

となるプログラムを組もうと、以下のようにスクリプトを書いたのですが、
上手く行きません。\x{5b65}…などの表記になります
また、入力ファイルを utf-8 に変えると euc-jpになります。
-----(ココから)-----
#!/usr/local/bin/perl -Tw
use strict;
use encoding 'euc-jp', STDOUT => 'iso-2022-jp';
#use encoding 'euc-jp', STDIN => 'euc-jp', STDOUT => 'iso-2022-jp';

print "Content-Type: text/html; charset=ISO-2022-JP\n\n";
open IN,'<','./index.html' or die $!;
my @data = <IN>;
close IN;
print @data;
-----(ココまで)-----

次に以下も試してみましたが、結果はeuc-jpのままでした
-----(ココから)-----
#!/usr/local/bin/perl -Tw
use strict;
use Encode qw/from_to/;

print "Content-Type: text/html; charset=ISO-2022-JP\n\n";
open IN,'<','./index.html' or die $!;
while(<IN>){
	from_to($_, 'euc-jp', 'iso-2022-jp');
	print;
}
close IN;
-----(ココまで)-----

perldoc encoding …や
Googleで見つかる各サイトの情報をみても
次に何を試せば良いかも見当が付きません。
ご存知の方、なにかアドバイスを頂けないでしょうか?

---(以下動作環境)----
$ uname -a
SunOS gitan 5.8 Generic_108528-19 sun4u sparc SUNW,Ultra-60
$ perl -V
Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=solaris, osvers=2.8, archname=sun4-solaris
    uname='sunos solaris 5.8 generic_108528-11 sun4u sparc sunw,ultra-5_10 '
    config_args='-Dcc=gcc -B/usr/ccs/bin/'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=unde
f
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc -B/usr/ccs/bin/', ccflags ='-fno-strict-aliasing -D_LARGEFILE_SOURCE
 -D_FILE_OFFSET_BITS=64',
    optimize='-O',
    cppflags='-fno-strict-aliasing'
    ccversion='', gccversion='3.1', gccosandvers='solaris2.8'
    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', lseeksize
=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc -B/usr/ccs/bin/', ldflags =' -L/usr/local/lib '
    libpth=/usr/local/lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -lgdbm -ldl -lm -lc
    perllibs=-lsocket -lnsl -ldl -lm -lc
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  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):
  Compile-time options: USE_LARGE_FILES
  Built under solaris
  Compiled at Jul 22 2002 02:55:19
  @INC:
    /usr/local/lib/perl5/5.8.0/sun4-solaris
    /usr/local/lib/perl5/5.8.0
    /usr/local/lib/perl5/site_perl/5.8.0/sun4-solaris
    /usr/local/lib/perl5/site_perl/5.8.0
    /usr/local/lib/perl5/site_perl
    .
---------1---------2---------3---------4---------5---------6---------7
        凸版印刷株式会社 関西商印事業部 販売促進本部
        Eビジネス部 Eビジネス課 システムソリューションG
          片松 祐司  (Yuji Katamatsu)
        E-mail: yuji.katamatsu at toppan.co.jp
        TEL 06(6454)3228  FAX 06(6454)3028  トールダイヤル 8-81-3228




More information about the Kansai-pm mailing list