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 6856781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:55:45+00:00 2026-05-27T01:55:45+00:00

I was trying out an elementary Perl/CGI script to keep track of visitors coming

  • 0

I was trying out an elementary Perl/CGI script to keep track of visitors coming to a web page. The Perl code looks like this:

#!/usr/bin/perl
#KEEPING COUNT OF VISITORS IN A FILE
use CGI':standard';
print "content-type:text/html\n\n";
#opening file in read mode
open (FILE,"<count.dat");
$cnt= <FILE>;
close(FILE);
$cnt=$cnt+1;
#opening file to write
open(FILE,">count.dat");
print FILE $cnt;
close(FILE);
print "Visitor count: $cnt";

The problem is that the web page does not increment the count of visitors on each refresh. The count remains at the initital value of $cnt , ie `1“. Any ideas where the problem lies?

  • 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-05-27T01:55:46+00:00Added an answer on May 27, 2026 at 1:55 am

    You never test if the attempt to open the file handle works. Given a file which I had permission to read from and write to that contained a single number and nothing else, the code behaved as intended. If the file did not exist then the count would always be 1, if it was read-only then it would remain at whatever the file started at.

    More general advice:

    • use strict; and use warnings; (and correct code based on their complaints)
    • Use the three argument call to open as per the first example in the documentation
    • When you open a file always || handle_the_error_in($!);
    • Don’t use a file to store data like this, you have potential race conditions.
    • Get the name of the language correct
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying out Mojolicious web framework based on perl. And I have
I'm currently trying out db4o (the java version) and I pretty much like what
I'm trying out the following query: SELECT A,B,C FROM table WHERE field LIKE 'query%'
I trying out some problems in Google's Code Jam. For the question Store Credit
Trying out BizTalk with a web service call The request/response is working fine on
Trying out mechanize to scrape some content off an https asp site, it looks
Just trying out this IDE but it already looks better than NetBeans in terms
Was trying out some code with the EF code first method and ran into
Trying out the examples found on pleac.sf.net , I'm not able to get an
While trying out an experimental UINavigationController-based iPhone application, I ran into a problem when

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.