08/08/30 00:59:19
fuga.txtがあるかどうかを調べ、もしあるならあると言い、なければないと言い、ない場合はわざわざ作成してあげて、
作成したと言い、ある場合は、ファイルサイズを調べてレポートするプログラム。↓
binmode STDIN => ":encoding(cp932)";
binmode STDOUT => ":encoding(cp932)";
binmode STDERR => ":encoding(cp932)";
use Encode;
use feature qw( :5.10 );
system q|cls|;
#----------------------------------
my $bar = 'fuga.txt';
my $a=&file;
sub file{
if (-f $bar) {
print "ファイル".$bar."が存在します。\n";
return 1;
}
else {
print"ファイル". $bar."が存在しません。\n";
return 0;
}
}
given($a){
when (1){
my $file_size;
$file_size = (stat'./fuga.txt')[7];
say $bar."のファイルサイズは、".$file_size."バイトです"; }
when (0){
open FH, ">fuga.txt";
say "ファイル". $bar."を作成しました。";
}
}