Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Undeclared CGI???

by Nickd_69 (Novice)
on Aug 13, 2003 at 04:03 UTC ( [id://283431]=perlquestion: print w/replies, xml ) Need Help??

Nickd_69 has asked for the wisdom of the Perl Monks concerning the following question:

I have the following script but the error I get in my error log is something like that CGI is not declared on line 8 and the script was aborted due to compilation errors. Could someone have a quick look? I am only a newbie to perl so don't get frustrated with me please.
#!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use Mail::Mailer; my $query = CGI->new(); my %DATA = $query->Vars; my $mailer = new Mail::Mailer ( "smtp" ); $mailer->open( { To => 'info@travancoresch.vic.edu.au', From => $DATA{Email}, Subject => 'Travancore School Professional Development' } ); print $mailer "$DATA{Title}\n"; print $mailer "$DATA{Name}\n"; print $mailer "$DATA{Position}\n"; print $mailer "$DATA{School}\n"; print $mailer "$DATA{Address}\n"; print $mailer "$DATA{Suburb}\n"; print $mailer "$DATA{State}\n"; print $mailer "$DATA{PCode}\n"; print $mailer "$DATA{Email}\n"; print $mailer "$DATA{Tel}\n"; print $mailer "$DATA{Fax}\n"; print $mailer "$DATA{Att1}\n"; print $mailer "$DATA{Att2}\n"; print $mailer "$DATA{Att3}\n"; $mailer->close; print $query->redirect('http://www.travancoresch.vic.edu.au/developmen +t/reply02.html');

Replies are listed 'Best First'.
Re: Undeclared CGI???
by chromatic (Archbishop) on Aug 13, 2003 at 04:33 UTC

    It looks fairly solid to me. Can you run it from the command-line? What version of Perl are you running? What is the output of these commands?

    perl -V perl -MCGI -e "print CGI->VERSION()"
      I am running perl version 5.6.1 which I'm pretty sure is the latest. The other command doesn't appear to work. Just comes up with heaps of errors. i have been trying to download and install all the extra modules that it requires but it is never ending. Any other ideas because there are compilation errors whihc must mean that some code is wrong somewhere???
        It looks like you don't have CGI.pm installed (???). Try installing that. Other than that quote the exact error here and we will probably have more luck.
Re: Undeclared CGI???
by sgifford (Prior) on Aug 13, 2003 at 05:03 UTC
    Why don't you try starting with a very simple program:
    #!/usr/bin/perl -w use strict; use CGI;

    If that works, try adding in a line:

    my $query = CGI->new();

    If it still works, add in another line and whatever modules it requires, and so forth. That should help you narrow down exactly where the error is occuring.

Re: Undeclared CGI???
by snadra (Scribe) on Aug 13, 2003 at 11:04 UTC
    I am running perl version 5.6.1 which I'm pretty sure is the latest
    No, it is not. It's Perl 5.8.0
    But that is not causing the problem. If you want to upgrade, do it, otherwise just reinstall CGI.pm.

    snadra
Re: Undeclared CGI???
by mildside (Friar) on Aug 13, 2003 at 04:51 UTC
    Try replacing your use CGI; with use CGI qw/:standard /; and see if the error still occurs.

    Cheers!

      Tried what you said but giving this error now: Undefined subroutine CGI::Vars. Any more Ideas? Thanks for your help guys.

        The Vars() method was added in version 2.50 of CGI.pm - which is older than the version in perl 5.00503 core (2.56) so you have either got an older version of perl than the one you think you have or you are picking up the CGI module from elsewhere.

        /J\
        
        Sounds like an incomplete or incorrect installation of the CGI module perhaps?

        Cheers!

        To get the CGI Vars method, you must import the :cgi-lib functions. Add it to your 'use CGI' line. Read all about it here: perldoc CGI

        use CGI qw(:standard :cgi-lib);

        YuckUse

Re: Undeclared CGI???
by chanio (Priest) on Aug 14, 2003 at 03:30 UTC
    I don't have Mail::Mailer but I would bet on that line that says ...

    my $mailer = new Mail::Mailer ( "smtp" );

    should have the address of your ISP's smtp. If you don't know it, try this address and fill the form with your email address...

    http://www.xav.com/mx_lookup.pl

    Then copy the smtp address to that line.

    Hope it helps!

      Tried what you said which seems like a good idea but I copied the address that I recieved and pasted it in but I am still getting the same error message Undefined subroutine CGI::Vars. I guess this must be a pretty bad error cause no one has solved it yet including me!!! You put the adress here dont you??
      my $mailer = new Mail::Mailer ( "ADDRESS HERE);
      If anyone can find a working solution then they will be one mighty good perl monk!
Re: Undeclared CGI???
by mildside (Friar) on Aug 14, 2003 at 04:53 UTC
    A few questions for you Nickd_69

  • Who maintains the server that this script will run on? Perhaps you should contact them about your problem with their installation of CGI.pm
  • Could it be a problem with the include path? This may be fixable with the use of a -I in the shebang line
  • Cheers!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://283431]
Approved by Zaxo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-20 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found