#!/usr/bin/perl # fortune - ことわざ表示 # Copyright (C) Takashi Utsunomiya. All Rights Reserved. # 2002.10.16- # ver 1.00 2002.10.16 # ■init use strict; # データファイル名(絶対パスで書くのが簡単) my $data_file = './fortune.dat'; # メッセージを毎回変える: 0 日毎に変えるか: 1 my $is_daily = 0; my @fortune; $ENV{'TZ'} = "JST-9"; main(); exit; # ■main sub main { init_rand(); set_fortune(); put_fortune(); } # ◆init_rand sub init_rand { my ($sec, $min, $hour, $day, $month, $year) = localtime(time); $_ = $year*1200 + $month*100 + $day; if ($is_daily) { srand($_); } else { srand(time|$$); } } # ◆set_fortune sub set_fortune { open(IN, $data_file) or die $!; foreach () { chomp; next if (/^$/); s/\\n/\n/g; push(@fortune, $_); } close(IN); } # ◆put_fortune sub put_fortune { print $fortune[int(rand() * @fortune)]; }