Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8236047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:01:14+00:00 2026-06-07T19:01:14+00:00

I am working on a cgi script for a number guessing game and I

  • 0

I am working on a cgi script for a number guessing game and I want to store the target value in a readable and writeable file. I don’t know how to do that, but I believe I can use a system() call to do it and some type of expression to extract the value from that file. I need help determining that solution; I have the following already:

#!/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";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:01:17+00:00Added an answer on June 7, 2026 at 7:01 pm

    Use open to open a file.

    use strict;
    
    # Get number
    open(my $infh, '<', '/path/to/file') or die "Cannot open: $!";
    my $number = <$infh>;
    close($infh);
    chomp($number); # removes newline, just in case
    
    # Save number
    open(my $outfh, '>', '/path/to/file') or die "Cannot open: $!";
    print $outfh $number;
    close($outfh);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Perl CGI script that isn't working and I don't know how
I have this simple cgi script working just fine but I want to add
I'm working on an audio encoder cgi script that utilises libmp3lame. I'm writing in
I have been working on getting a python CGI script to work all day,
I’m working on a Perl CGI script about 4000 lines big. Our coding style
I want users access the cgi script for searching tags in my blog, but
I have a CGI script that generates a file on the server and then
I'm working on a CGI script that is called from a piece of software
Working on a small game using an HTML5 canvas, and javascript. And it's working
Working with an undisclosed API, I found a function that can set the number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.