I knew I was missing something. So here is my revised script:
#!/usr/bin/perl -Tw use strict; use CGI; use Fcntl qw(:flock); my $CGI = new CGI; my $file; my $countfile="downloadcounts.txt"; my $OS_Type=$CGI->param("OS"); my %OS_Count=(); my $OS_Name; my $count; open(COUNT,"$countfile")||die"Can't open: $!\n"; flock(COUNT,LOCK_SH); while(<COUNT>){ if(/^$/){}else{ ($OS_Name,$count)=split /=/; chomp($OS_Name); chomp($count); $OS_Count{$OS_Name}=$count; } flock(COUNT,LOCK_UN); close COUNT; if($OS_Type=~/Linux/ || $OS_Type=~/Windows/){ if(exists $OS_Count{$OS_Type}){ $OS_Count{$OS_Type}++; } &write(\%OS_Count); if($OS_Type=~/Windows/){ $file="http://tstanley.perlmonk.org/QuizTaker32-V108.zip"; $CGI->redirect($file); }elsif($OS_Type=~/Linux/){ $file="http://tstanley.perlmonk.org/QuizTaker-V1.08.tar.gz"; $CGI->redirect($file); }else{ print $CGI->header(); print $CGI->start_html('Try Again!'); print $CGI->h1(-align=>'center','Incorrect OS!!'); print $CGI->end_html(); } }elsif($OS_Type=~/Show/){ print $CGI->header(); print $CGI->start_html('Number of Downloads'); foreach my $key(keys %OS_Count){ print $CGI->h3("$key = $OS_Count{$key} downloads"); } print $CGI->end_html(); } sub write{ my $Hash=shift; open(COUNT,"+<$countfile")||die"Can't open: $!\n"; flock(COUNT,LOCK_EX); seek(COUNT,0,0); truncate(COUNT,0); foreach my $key (keys %$Hash){ print COUNT "$key=$$Hash{$key}\n"; } flock(COUNT,LOCK_UN); close COUNT; }
Thanks for all the great advice!

TStanley
--------
There's an infinite number of monkeys outside who want to talk to us
about this script for Hamlet they've worked out
-- Douglas Adams/Hitchhiker's Guide to the Galaxy

UPDATE: I loaded the above script, and am getting Internal server 500 errors. My error log shows the following:
[Tue Aug 21 19:54:01 2001] [error] [client 63.57.209.20] Premature end + of script headers: /home/tstanley/public_html/cgi-bin/download.cgi Missing right bracket at /home/tstanley/public_html/cgi-bin/download.c +gi line 68 , at end of line syntax error at /home/tstanley/public_html/cgi-bin/download.cgi line 6 +8, at EOF Execution of /home/tstanley/public_html/cgi-bin/download.cgi aborted d +ue to comp ilation errors. [Tue Aug 21 19:54:11 2001] [error] [client 63.57.209.20] Premature end + of script headers: /home/tstanley/public_html/cgi-bin/download.cgi Missing right bracket at /home/tstanley/public_html/cgi-bin/download.c +gi line 68 , at end of line syntax error at /home/tstanley/public_html/cgi-bin/download.cgi line 6 +8, at EOF Execution of /home/tstanley/public_html/cgi-bin/download.cgi aborted d +ue to comp ilation errors. [Tue Aug 21 19:55:09 2001] [error] [client 63.57.209.20] Premature end + of script headers: /home/tstanley/public_html/cgi-bin/download.cgi
The links that call the script look like this:
<A HREF="http://tstanley.perlmonk.org/cgi-bin/download.cgi?OS=Linux">L +inux</A>


UPDATE 2: I fixed the syntax error(forgot a } in the else statement where I read the file), but am still getting the premature end of script headers. I get these when I click on the links for Linux or Windows. Otherwise the script works when I show the number of downloads.

In reply to Re: Advice on a CGI script by TStanley
in thread Advice on a CGI script by TStanley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.