TStanley has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -Tw use strict; use CGI qw(:all); 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"; while(<COUNT>){ ($OS_Name,$count)=split /=/; chomp($OS_Name); chomp($count); $OS_Count{$OS_Name}=$count; } 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"; foreach my $key (keys %$Hash){ print COUNT "$key=$$Hash{$key}\n"; } close COUNT; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(Ovid) Re: Advice on a CGI script
by Ovid (Cardinal) on Aug 22, 2001 at 02:43 UTC | |
|
Re: Advice on a CGI script
by Beatnik (Parson) on Aug 22, 2001 at 02:43 UTC | |
|
Re: Advice on a CGI script
by blakem (Monsignor) on Aug 22, 2001 at 02:49 UTC | |
|
Re: Advice on a CGI script
by tachyon (Chancellor) on Aug 22, 2001 at 04:27 UTC | |
|
Re: Advice on a CGI script
by TStanley (Canon) on Aug 22, 2001 at 03:37 UTC | |
by Ovid (Cardinal) on Aug 22, 2001 at 04:48 UTC | |
|
Re: Advice on a CGI script
by jryan (Vicar) on Aug 22, 2001 at 02:33 UTC |