数値推測ゲームのcgiスクリプトに取り組んでおり、読み取りと書き込みが可能なファイルにターゲット値を保存したいと考えています。その方法はわかりませんが、system()呼び出しを使用してそれを実行し、ある種の式を使用してそのファイルから値を抽出できると思います。その解決策を決定するのに助けが必要です。私はすでに次のものを持っています:
#!/usr/bin/perl -w
use CGI qw(:standard);
print header, start_html("Guessing Game"), h2("Guessing game"), "\n";
//need some type of system call to store value if one does not exist
//or read it if it does (random value generated below)
srand( time() ^ ($$ + ($$ << 15)) );
my $target = int(rand 100) + 1;
if ( !param() ) {
print hr, "\n", start_form;
print p("Try to guess a number between 1 and 100: ", textfield("guess")), "\n";
print end_form, "\n", hr;
} else {
print hr, "\n", start_form;
my $guess = param("guess");
if ($guess > $target) {
print p ("$guess is too high; try again: ", textfield("guess")), "\n";
} elsif ($guess < $target) {
print p ("$guess is too low; try again: ", textfield("guess")), "\n";
} else {
print p ("You got it: $guess!");
//erase value from file
}
print end_form, "\n", hr;
}
print end_html, "\n";