Perl

でもサイトは、ここをクリック

	#!/usr/bin/perl
	use CGI;
	use strict;
	my $charset="utf-8";
	my $title="小樽商科大学";
	my $myself = './***.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|;
	#オプション追加 7桁 9桁 11桁
	
	
	
	
	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];
		my %B07;
		my %B09;
		my %B11;
		my $file = "***";#<--------------修正
		open(IN,$file);
		my @B = <IN>;
		close(IN);
		#単語検索 11桁の識別番号取得
		foreach(@B){
			my @tmp = split(/,/,$_);#004994,04746,A,体,関係,作用,走り・飛び・流れなど,1.1522,05,06,01,暴走,暴走,ぼうそう,うそうぼ
			#if($tmp[12] =~ /$word/){#「廃止」を入力した場合、「廃止する」も表示される。
			if($tmp[12] eq $word){
				print "$tmp[3] $tmp[4] $tmp[5] - $tmp[12] - $tmp[13] <br>\n";
				$B07{"$tmp[7]$tmp[8]"}++;
				$B09{"$tmp[7]$tmp[8]$tmp[9]"}++;
				$B11{"$tmp[7]$tmp[8]$tmp[9]$tmp[10]"}++;
			}
		}
		#途中経過
		print $q->h3("途中経過");
		my @B07 = keys %B07;
		my @B09 = keys %B09;
		my @B11 = keys %B11;
		print $q->h4("07桁");
		print "<ol>\n";
		foreach(@B07){ print "<li>$_($B07{$_})</li>\n";}
		print "</ol>\n";
		print $q->h4("09桁");
		print "<ol>\n";
		foreach(@B09){ print "<li>$_($B09{$_})</li>\n";}
		print "</ol>\n";
		print $q->h4("11桁");
		print "<ol>\n";
		foreach(@B11){ print "<li>$_($B11{$_})</li>\n";}
		print "</ol>\n";
	
	
		#識別番号を利用して、類似検索
		my %B07list;
		my %B09list;
		my %B11list;
		foreach(@B){
			my @tmp = split(/,/,$_);#004994,04746,A,体,関係,作用,走り・飛び・流れなど,1.1522,05,06,01,暴走,暴走,ぼうそう,うそうぼ
			my $tmpB07 = "$tmp[7]$tmp[8]";
			my $tmpB09 = "$tmp[7]$tmp[8]$tmp[9]";
			my $tmpB11 = "$tmp[7]$tmp[8]$tmp[9]$tmp[10]";
			if($B07{$tmpB07}){$B07list{$tmp[12]}++;}
			if($B09{$tmpB09}){$B09list{$tmp[12]}++;}
			if($B11{$tmpB11}){$B11list{$tmp[12]}++;}
		}
		
		#拡張結果
		print $q->h3("拡張結果");
		my @B07list = keys %B07list;
		my @B09list = keys %B09list;
		my @B11list = keys %B11list;
		print $q->h4("11桁(拡張なし)");
		print "<ol>\n";
		foreach(@B11list){ print "<li>$_($B11list{$_})</li>\n";}
		print "</ol>\n";
		print $q->h4("09桁(拡張 少)");
		print "<ol>\n";
		foreach(@B09list){ print "<li>$_($B09list{$_})</li>\n";}
		print "</ol>\n";
		print $q->h4("07桁(拡張 多)");
		print "<ol>\n";
		foreach(@B07list){ print "<li>$_($B07list{$_})</li>\n";}
		print "</ol>\n";
	
	}