Perl

デモサイトはこちら

	#!/usr/bin/perl
	use CGI;
	my $charset="utf-8";
	my $title="小樽商科大学";
	my $myself = './index.cgi';#<------------------修正
	my $q = new CGI;
	print $q->header(-charset=>$charset);
	print $q->start_html(-title=>$title, -encoding=>$charset);
	#時間
	my @time = localtime(time);
	$time[4]++;
	$time[5] += 1900;
	#foreach(@time){ print "$_/";}
	print "<br>$time[5]月$time[4]月$time[3]日$time[2]時$time[1]分$time[0]秒<br>\n";
	print "$ENV{'REMOTE_ADDR'}<br>\n";
	
	
	#入力単語
	print "入力:" . $q->param('user') . "<br>\n";
	if($q->param('user')){
		&Log($q->param('user'));
		&Search($q->param('user'));
	}
	
	print $q->start_form(-method => 'POST', -action => $myself);
	print qq|<input type="text" size="30" name="user" value="廃止">\n|;
	print qq|<input type="submit" name="submit" value="送信">\n|;
	print $q->end_form();
	print $q->end_html();
	
	
	sub Log(){
		my $word = $_[0];
		#LOG
		open(OUT,">>***");#<--------------修正
		print OUT "$time[5]月$time[4]月$time[3]日$time[2]時$time[1]分$time[0]秒\t$ENV{'REMOTE_ADDR'}\t$word\n";
		close(OUT);
	}
	
	sub Search()
	{
		my $word = $_[0];
		$file = "****";#<---------------修正
		open(IN,$file);
		while(<IN>){
			@tmp = split(/,/,$_);#004994,04746,A,体,関係,作用,走り・飛び・流れなど,1.1522,05,06,01,暴走,暴走,ぼうそう,うそうぼ
			if($tmp[12] =~ /$word/){
				print "$tmp[3] $tmp[4] $tmp[5] - $tmp[12] - $tmp[13] <br>\n";
			}
		}
		close(IN);
	}