--- Jeremy Gray <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm only a couple days into learning perl here.. but I've been having this
> problem with subroutines I can't seem to figure out. Could someone explain
> what I'm doing wrong here:
>
> require "cgi-lib.pl";
Please don't use cgi-lib.pl. It's old, out-of-date Perl4 technology and it is no
longer being
maintained. You'll find CGI.pm is what is currently being used and it is included in
the standard
Perl distribution.
> &ReadParse;
> #print &PrintHeader;
>
> if ( $in{'agree'} ne "" ) {
>
> #### THE PROBELM IS HERE.. I just want it to run the
> #### doStore sub, then run the doRedirect sub.. but
> #### I'm not sure on the syntax of how to do it.
>
> &doStore;
> &doRedirect;
Your syntax is correct, assuming that &ReadParse populates the %in hash. I *though*
that it
populated something like %formdata, but I could be wrong. However, rather than
tracking down this
problem, I cleaned up your code a bit to show you how to use CGI.pm. I have tested
this code and
it appears to work fine.
#!/usr/bin/perl -wT
use strict;
use CGI qw/:standard/;
require "ctime.pl"; # ? Don't know this module
my $date = ctime(time);
chomp($date);
my $datafile = "harvest.txt";
my $URL = "http://www.cnet.com/";
my $ip = $ENV{'REMOTE_ADDR'};
if ( param( 'agree' ) ne "" ) {
&doStore;
&doRedirect;
} else {
&doSorryNoAgree;
}
sub doSorryNoAgree {
print header;
print <<END_HTML;
<html>
<head>
<title>Oops!</title>
</head>
<body bgcolor="#ffffff">
<table align="center" bgcolor="#000000" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<table align="center" bgcolor="#FFFFFF" border="0" cellpadding="2"
cellspacing="2"
width="100%">
<tr>
<td align="center" bgcolor="#0000FF">
<b><font face="arial" size="5">Error!</font></b>
</td>
</tr>
<tr>
<td>
<font face="arial">The check box must be checked first.</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
END_HTML
}
sub doStore {
my $username = param( 'username' );
my $password = param( 'password' );
my $email = param( 'email' );
# always add the 'or die' after an open so you can know if it worked!
open(OUTFILE, ">> $datafile") or die "Cannot open $datafile for appending: $!";
print OUTFILE "\n$date | $username | $password | $email | $ip";
close(OUTFILE);
}
sub doRedirect {
print redirect( $URL ); # This handy CGI.pm function handles your "Location:"
header for you
}
=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.com/