#!/usr/bin/perl # 現在日時を求めてhnfファイルに追加する use File::Copy; # hnfの格納ディレクトリ(年名は除外。後で追加する) $hnfdir = 'c:/home/diary/'; # hnfのテンプレート(ファイルが作成されてなかった際に利用される) $hnftemplate = 'c:/home/diary/hnf-template.txt'; # ユーザ変数 $uservar = 'SUIMIN'; @youbi = ('日', '月', '火', '水', '木', '金', '土'); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year += 1900; $mon += 1; print "$year 年 $mon 月 $mday 日 ($youbi[$wday]) $hour 時 $min 分 $sec秒 \n"; $hnfdir = "$hnfdir$year/"; $hnffile = $hnfdir . sprintf("d%04d%02d%02d.hnf", $year, $mon, $mday); $ntmstr = sprintf("%02d:%02d", $hour, $min); print "$hnfdir\n"; print "$hnffile\n"; print "$ntmstr\n"; print '-' x 20 , "\n"; if (-e $hnffile) { print "$hnffile が存在します。\n"; } else { print "$hnffile が存在しません。$hnffileを作成します。\n"; copy($hnftemplate, $hnffile); } @list = (); open(IN,$hnffile) || &err("$hnffile が開けませんでした。"); binmode(IN); while() { chomp; if ( /^$uservar / ) { $_ .= " $ntmstr"; } push(@list,$_); } close(IN); open(OUT,">$hnffile" ) || &err("$hnffile が開けませんでした。"); binmode(OUT); foreach $str (@list) { print OUT "$str\n"; } close(OUT); print "\n$hnffile に現在時刻を追加しました。\n"; sleep(5); exit; sub err { $msg = $_[0]; print "\nError : $msg\n"; print "\nPush Any Key"; $t = getc; exit; }