初めてのPerl ~ 13章 ファイルとディレクトリの取り扱い ~
13.1 ファイルを削除する
unlink を用いて指定ファイルを削除する
#!/usr/bin/perl
use warnings;
use strict;foreach(<@ARGV>){
unlink $_ or warn "Can't delete $_ : $!\n";
}
13.2 ファイルの名前を変更する
rename を用いてファイルの名前を変更する
#! /usr/bin/perl
use warnings;
use strict;foreach my $file( glob "*.pl" ){
my $newfile = $file;
$newfile =~ s/\.pl$/.pm/;
if(-e $newfile){
warn "can't rename $file to $newfile : $newfile exists\n";
}
elsif(rename $file,$newfile){
}
else{
warn "rename $file to $newfile failed:$!\n";
}
}
参考書
- 作者: ランダル・L.シュワルツ,トムフェニックス,Randal L. Schwartz,Tom Phoenix,近藤嘉雪
- 出版社/メーカー: オライリージャパン
- 発売日: 2003/05
- メディア: 単行本
- 購入: 15人 クリック: 474回
- この商品を含むブログ (273件) を見る