FileHandleモジュールの使い方メモ
open関数やclose関数を使わず、FileHandleモジュールを使用するとオブジェクト風にファイルI/Oが出来ます。
FileHandleモジュールを使ったサンプルのメモ
use FileHandle;
$fh = new FileHandle;
if ($fh->open("< File.txt")) {
print <$fh>;
$fh->close;
}
$fh = new FileHandle "> File2.txt";
if (defined $fh) {
print $fh "testx\n";
$fh->close;
}
$fh = new FileHandle "File.txt", "r";
if (defined $fh) {
print <$fh>;
undef $fh;
}
$fh = new FileHandle "File2.txt", O_WRONLY|O_APPEND;
if (defined $fh) {
print $fh "testy\n";
undef $fh;
}