ファイルとディレクトリ

ファイルを削除する

#!/usr/bin/evn perl use strict; use warnings; use Path::Class; file('tmp.txt')->touch; file('tmp.txt')->remove or die "can't delete file"; See also: http://d.hatena.ne.jp/perlcodesample/20080520/1211255597

複数階層のディレクトリを作成する

#!/usr/bin/evn perl use strict; use warnings; use Path::Class; dir('foo','bar')->mkpath or die "can't create dir"; パス表現はPath::Classを使う事でCross Platformで扱う事ができます。See also http://d.hatena.ne.jp/perlcode…

ファイルを作成する

#!/usr/bin/env perl use strict; use warnings; use Path::Class; my $fh = file('tmp.txt')->openw; $fh->close; __END__ 作るだけであれば、touchでもよいと思います。See also: http://d.hatena.ne.jp/perlcodesample/20080519/1211252829

ファイル名から、ディレクトリ名とベース名を取り出す

#!/usr/bin/evn perl use strict; use warnings; use Path::Class; use Perl6::Say; my $file = file( 'foo', 'bar', 'tmp.txt' ); say $file->basename; say $file->dir; __END__ See also: http://d.hatena.ne.jp/perlcodesample/…