初めてのPerl ~ 11章 ファイルハンドルとファイルテスト ~
練習問題 11.7.3
コマンドラインからファイル名のリストを受け取って、
そのうち最も古いファイルの名前とその古さを日数単位で表示する
プログラムを書く
#! /usr/bin/perl
use warnings;
use strict;sub cmp_file{
die "There is not a file\n" unless @_;
my $old_file_name = shift @_;
my $old_file_age = -M $old_file_name;foreach (@_){
my $file_age = -M $_;
($old_file_name,$old_file_age) = ($_,$file_age) if( $old_file_age < $file_age );
}
printf "%s : %.lf days old \n", $old_file_name,$old_file_age;
}&cmp_file(@ARGV);
- 作者: ランダル・L.シュワルツ,トムフェニックス,Randal L. Schwartz,Tom Phoenix,近藤嘉雪
- 出版社/メーカー: オライリージャパン
- 発売日: 2003/05
- メディア: 単行本
- 購入: 15人 クリック: 474回
- この商品を含むブログ (273件) を見る