* Perlのファイルシステム関係 [#oef88de6]

** Perlのファイル演算子 [#g36bde3d]

|読みだし可能|-r |書き込み可能|-w|
|実行可能|-x |ユーサ所有|-o|
|存在している|-e |サイズ0|-z|
|サイズ0でない|-s |普通のファイル|-f|
|ディレクトリ|-d |シンボリックリンク|-l|
|ソケット|-S |名前付パイプ|-P|
|ブロックデバイス|-b |キャラクタデバイス|-c|
|テキストファイル|-T |バイナリファイル|-B|
|最終更新時刻からの日数|-M |最終アクセス時刻からの日数|-A|

** 現在のディレクトリを取得 [#j72b7882]
 use Cwd;
 $dir = cwd;

** ファイル比較 [#i1631894]
 use File::Compare;
 if (compare("file1","file2") == 0) {
     print "They're equal\n";
 }
** シリアライズ [#e89c696e]
*** Data::Dumper [#o6cbd011]
 use Data::Dumper;
 open(FILE,"> out.txt") || die;
 print FILE Data::Dumper->Dump([ $ref ]);
 close(FILE);

 use Data::Dumper;
 $ref = require("out.txt");

*** Storable(速い) [#n6eaf513]
 use Storable qw(store retrieve freeze thaw dclone);
 
 %color = ('Blue' => 0.1, 'Red' => 0.8, 'Black' => 0, 'White' => 1);
 
 store(\%color, '/tmp/colors') or die "Can't store %a in /tmp/colors!\n";
 
 $colref = retrieve('/tmp/colors');
 die "Unable to retrieve from /tmp/colors!\n" unless defined $colref;
 printf "Blue is still %lf\n", $colref->{'Blue'};
 
 $colref2 = dclone(\%color);
 
 $str = freeze(\%color);
 printf "Serialization of %%color is %d bytes long.\n", length($str);
 $colref3 = thaw($str);
****参考 [#c71a181c]
http://perldoc.jp/docs/modules/Storable-2.05/Storable.pod


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS