use encode - yokohama.pm#6 x perl-casual#3
DESCRIPTION
TRANSCRIPT
![Page 1: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/1.jpg)
use Encode;
@xaicron
2010/07/23yokohama.pm over perlcasual
2010年7月24日土曜日
![Page 2: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/2.jpg)
自己紹介
• Yuji Shimada / 嶋田 裕二
• twitter: @xaicron
• work: DeNA
2010年7月24日土曜日
![Page 3: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/3.jpg)
今日言いたいことは
2010年7月24日土曜日
![Page 4: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/4.jpg)
decodeしていじって
encodeする
2010年7月24日土曜日
![Page 5: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/5.jpg)
ってことです!!
2010年7月24日土曜日
![Page 6: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/6.jpg)
WARNING!!
2010年7月24日土曜日
![Page 7: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/7.jpg)
• require jcode.pl;
• use encoding ‘euc-jp’;
• use open IN => ‘:encoding(euc-jp)’;
• ( use Jcode )
2010年7月24日土曜日
![Page 8: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/8.jpg)
レガシーなコード
2010年7月24日土曜日
![Page 9: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/9.jpg)
忘れてください
2010年7月24日土曜日
![Page 10: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/10.jpg)
what’s Encode?
2010年7月24日土曜日
![Page 11: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/11.jpg)
マルチバイト文字列を扱うときのデファクト
2010年7月24日土曜日
![Page 12: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/12.jpg)
バイト文字列をperlの内部文字列(flagged utf8)にしたり
2010年7月24日土曜日
![Page 13: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/13.jpg)
その逆をしたりする
2010年7月24日土曜日
![Page 14: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/14.jpg)
そんな小粋なモジュールだよ!
2010年7月24日土曜日
![Page 15: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/15.jpg)
なにがうれしいの?
2010年7月24日土曜日
![Page 16: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/16.jpg)
octet base じゃなくcharacter base のコーディングが出来るということ
2010年7月24日土曜日
![Page 17: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/17.jpg)
Core Module
2010年7月24日土曜日
![Page 18: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/18.jpg)
maintainer is dankogai
2010年7月24日土曜日
![Page 19: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/19.jpg)
2010年7月24日土曜日
![Page 20: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/20.jpg)
WARNING!!
2010年7月24日土曜日
![Page 21: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/21.jpg)
perl 5.8.1 以上出来れば 5.8.8 以上を
使うこと
2010年7月24日土曜日
![Page 22: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/22.jpg)
掟
2010年7月24日土曜日
![Page 23: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/23.jpg)
其の壱
2010年7月24日土曜日
![Page 24: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/24.jpg)
外部から来たものはすべて decode
すべし!!
2010年7月24日土曜日
![Page 25: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/25.jpg)
外部入力の例• 引数(@ARGS の中身)
• STDIN, ファイル読み込み
• DBからとってきたデータ
• HTTPとかでとってきたデータ
• etc..
2010年7月24日土曜日
![Page 26: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/26.jpg)
とにかく入力と思われるものすべて
2010年7月24日土曜日
![Page 27: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/27.jpg)
其の弐
2010年7月24日土曜日
![Page 28: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/28.jpg)
外部に出力するものはすべて encode
すべし!
2010年7月24日土曜日
![Page 29: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/29.jpg)
外部出力の例• STDOUT, STDERR
• ファイル書き込み
• DBに書き込むデータ
• レンダリングするHTML
• etc..
2010年7月24日土曜日
![Page 30: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/30.jpg)
これを守ると幸せになれます!!
2010年7月24日土曜日
![Page 31: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/31.jpg)
• decode
• 「任意の」バイト文字列を内部文字列に変換
• encode
• 内部文字列を「任意の」バイト文字列に変換
2010年7月24日土曜日
![Page 32: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/32.jpg)
バイト文字列とは
• 我々が文字列だと思っているものは、実はバイトの連続だ!
• 適切なキャラセットでエディターとかがマッピングしてるから文字に見えるよ!
2010年7月24日土曜日
![Page 33: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/33.jpg)
バイト文字列とは
• プログラム的にはバイト文字列はアレゲ
• 一文字を一文字として扱えない(length
でバイト数が帰ってくる)
2010年7月24日土曜日
![Page 34: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/34.jpg)
内部文字列とは• 一文字がプログラム的に一文字として扱われる状態
• length で文字数が帰ってくる
• 正規表現とかsubstrとかsplitとかウマーな状態
2010年7月24日土曜日
![Page 35: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/35.jpg)
$ perl -E ‘say length “あいうえお”’
15 $ perl -MEncode -E ‘say length decode utf8 => “あいうえお”’
5
2010年7月24日土曜日
![Page 36: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/36.jpg)
Encodeの使い方use strict;use warnings;use Encode;
my $str = decode utf8 => “だんこがい”;
# do something...print encode utf8 => $str;
2010年7月24日土曜日
![Page 37: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/37.jpg)
簡単ですね!
2010年7月24日土曜日
![Page 38: use Encode - yokohama.pm#6 x perl-casual#3](https://reader035.vdocuments.net/reader035/viewer/2022081414/54c8dba04a7959272d8b4642/html5/thumbnails/38.jpg)
続きはWebで!http://perl-users.jp/articles/advent-calendar/2009/casual/
10.html
2010年7月24日土曜日