2004년 2월 26일 목요일

iconv

man iconv -a
: Convert encoding of given files from one encoding to another

iconv의 문제점
- illegal한 byte sequence가 나타나면 더 이상 처리하지 않고 종료함.
그래서 뒷부분이 잘려버림.

iconv(3) 함수의 에러 발생 1번 case
       1.  An  invalid multibyte sequence is encountered in the input. In this
       case it sets errno to EILSEQ and returns (size_t)(-1). *inbuf  is  left
       pointing to the beginning of the invalid multibyte sequence.

해결책
perl 5.8.0의 Encode모듈을 이용하면 잘못된 내용은 skip하고 변환해줌
#!/usr/bin/perl
use Encode qw(from_to);

while(<STDIN>){
    from_to($_, "utf-8", "euc-kr", 0);
    print $_;
}

댓글 없음:

댓글 쓰기