Tripletail::CSV - CSV のパースと生成
# パース my $csv = $TL->getCsv; my $parser = $csv->parseCsv($CGI->getFile('upload')); while (my $row = $parser->next) { # $row: ['カラム1', 'カラム2', ...] } # 生成 $TL->print($csv->makeCsv([ qw(aaa bbb ccc) ]), "\n"); $TL->print($csv->makeCsv([ qw(aaa bbb ccc) ]), "\n");
CSV のパースと生成を行う為のクラス。 カンマを含むカラム、改行コードを含むカラム等も 正しく処理する事が出来る。
文字列のパースの他に、ファイルハンドルからのパースも可能。
$TL->getCsv
my $csv = $TL->getCsv;
Tripletail::CSV オブジェクトを取得する。
parseCsv
my $parser = $csv->parseCsv("a,b,c,d,e"); my $parser = $csv->parseCsv(IO::Scalar->new(\"a,b,c,d,e"));
与えられた文字列またはファイルハンドルから パーサオブジェクトを生成する。
返されたオブジェクトに対して next メソッドを一度呼ぶ度に、 一行分のデータが配列リファレンスで返される。 最後の行を読んだ後は undef が返される。
next
while (my $row = $parser->next) { ... }
CSV に問題があってパースできない場合は、next メソッドを呼んだ 時に例外が発生する。
makeCsv
my $line = $csv->makeCsv([1, 2, 3]);
与えられた配列リファレンスから CSV 1行を生成して返す。 戻り値の末尾に改行文字は付加されない。
このモジュールは Text::CSV_XS に依存しており、もしそれが利用可能 でない状態で $TL->getCsv を呼ぶと例外が発生する。
Copyright 2006 YMIRLINK Inc. All Rights Reserved.
This framework is free software; you can redistribute it and/or modify it under the same terms as Perl itself
このフレームワークはフリーソフトウェアです。あなたは Perl と同じライセンスの 元で再配布及び変更を行うことが出来ます。
Address bug reports and comments to: tl@tripletail.jp
HP : http://tripletail.jp/
To install Tripletail, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tripletail
CPAN shell
perl -MCPAN -e shell install Tripletail
For more information on module installation, please visit the detailed CPAN module installation guide.