ファイル名: w/spaceship_operator.cgi

#!/usr/local/bin/perl

#------------------------------------------------------------
$Title = 'spaceship_operator';
$BODY = '<BODY BGCOLOR="#000000" TEXT="#C0C0C0">';
$FONT_R = '<font color="#FF0000">';
$FONT_G = '<font color="#00FF00">';
$FONT_C = '</font>';
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>$Title</TITLE></HEAD>\n";
print "$BODY\n";
print "<blockquote>\n";
#------------------------------------------------------------
@suuji = (1,2,3,7,9,13,110,56,22);
@usojun = sort@suuji;
@jun = sort{$a <=> $b}@suuji;
print "$FONT_G\@suuji @suujiを。ソート(sort)する。$FONT_C \n";
print "<BR><BR>\n";
print "@usojun\n";
print "<BR><BR>\n";
print "$FONT_G\@suuji @suujiを。スペースシップ演算子を使ってソート(sort)する。$FONT_C \n";
print "<BR><BR>\n";
print "@jun\n";
print "<BR><BR>\n";
print "<HR>\n";
#----------------------------------------------------------
print "掲示板の記事\n";
print "<BR><BR>\n";
if(!open(IN,"ware.txt")) { print "エラー<BR><BR>\n";}
@array = <IN>;
close(IN);
($date,$name,$email,$comment) = split(/\,/,@array);
print "<div align=center><center>\n";
foreach $line (@array ) {
chop;
($date,$name,$email,$comment) = split(/\,/,$line);
$comment =~ s/\r/<br>/g;
if ($email ne "") {
print "<a href=mailto:$email><strong>$name</strong></a>\n";
} else { print "<strong>$name</strong>\n"; }
print "$date<br>\n";
print "$comment\n";
print "<HR NOSHADE SIZE=1 WIDTH=\"500\" ALIGN=CENTER>\n";
}
print "</center></div>\n";
print "<HR>\n";
#----------------------------------------------------
print "掲示板の記事を、名前順にソートして、コメントをみる。\n";
print "<BR><BR>\n";
if(!open(WAREWAN,"ware.txt")) { print "エラー<BR><BR>\n";}
@array = <WAREWAN>;
close(WAREWAN);
($date,$name,$email,$comment) = split(/\,/,@array);
foreach $line (@array ) {
chop;
($date,$name,$email,$comment) = split(/\,/,$line);
$comment =~ s/\r/<br>/g;
$a {$name} = $comment;
}
print "<div align=center><center>\n";
for (sort by_junnban keys(%a)){
print " $_ <BR>$a{$_}<HR NOSHADE SIZE=1 WIDTH=\"500\" ALIGN=CENTER>\n";
}#----サブルーチンの&は省略可
print "</center></div>\n";
sub by_junnban {
($junnban{$a} cmp $junnban{$b}) || ($a cmp $b)
}

print "<BR><BR>\n";
print "$FONT_R同じ名前は、1つしかでない問題、大文字、小文字の変換比較して、元の名前を出す問題は、<BR>ますます面倒になりそうで、やめました。$FONT_C \n";
#------------------------------------------------------------
print "</blockquote>\n";
print "</BODY>\n";
print "</HTML>\n";
exit;