> Is this how you were talking about getting rid of globals, and does this > seem correct? > > #!/usr/bin/perl -T > > use strict; > use warnings; > > use lib '/home/perl-lib/modules'; > > use CGI; > use Email::Valid; > use Mail::Mailer; > > my $q = CGI->new(); > > print $q->header(); > > check_fields($q); >
In the above you are passing the query object but then in the subroutine you don't retrieve it. Try moving your subs to before the main code or put them in a separate file. You will see how Perl will complain. > sub check_fields { > my @fields = qw(name email city state message); > foreach my $field (@fields) { > next if ($q->param($field)); You are still access $q in the main:: rather than the one you passed to the subroutine because you have never retrieved it from @_. Try switching the name from $q to something else, like $query, that will break the script and prevent the stricture check from passing, then without switching the name back correct the script. That will point out the issue. > print 'Please fill in the blank fields.\n'; > exit; > } > unless (Email::Valid->address($q->param('email'))) { > print 'The email address entered was invalid.\n'; > } > } > > sub send_email { > my $q = shift; This appears to be correct, you might consider using a different name, just to prevent confusion, at least as long as the subs live in the same file. I didn't see where your call to 'send_email' went though... > my $m = Mail::Mailer->new('sendmail'); > $m->open({ From => $q->param('email'), > To => 'perl <[EMAIL PROTECTED]>', > Subject => '[INFO] Site Comment', > }) or die $!; > print $m "Name: " . ucfirst($q->param('name')) . "\n"; > print $m "Location: " . ucfirst($q->param('city')) . ", " . > $q->param('state') . "\n\n"; > print $m $q->param('message'); > $m->close(); > } > > http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>