Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

How to pass a parameter between cgi's?

by JaredF (Initiate)
on Oct 24, 2005 at 00:22 UTC ( #502351=perlquestion: print w/replies, xml ) Need Help??

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

I'm having a frustrating time passing a single parameter between two perl .cgi programs (cgi1.cgi & cgi2.cgi). In particular, perl complains like this: Can't call method "param" on an undefined value at C:\Program Files\OptiPerl\Webroot\cgi-bin\cgi2.cgi line 5.
What am I ignorant of (this time)?
Jared
##############CGI1.CGI############### #!/usr/local/bin/perl use CGI qw(:all); print header; print "now in cgi1.cgi<BR>"; print q(<A HREF="./cgi2.cgi?i=99">go to cgi2</A>); ##############CGI2.CGI############### #!/usr/local/bin/perl use CGI qw(:all); print header; print "in cgi2.cgi<BR>"; $i = $query->param('i'); print $i;

Replies are listed 'Best First'.
Re: How to pass a parameter between cgi's?
by dragonchild (Archbishop) on Oct 24, 2005 at 00:25 UTC
    In CGI2.CGI, where are you defining $query? It looks to me as if you cut'n'pasted some code from someone else without a full understanding of what it's doing.

    Try either of the following approaches:

    • #!/usr/local/bin/perl use CGI qw(:all); print header; print "in cgi2.cgi<BR>"; $i = param('i'); print $i;
    • #!/usr/local/bin/perl use CGI; $query = CGI->new; print $query->header; print "in cgi2.cgi<BR>"; $i = $query->param('i'); print $i;

    Update: $CGI -> CGI in the second code example.


    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
      Dragonchild --
      Code sample #1 works like a charm. Thank you.
      In response to your question -- "In CGI2.CGI, where are you defining $query." -- the answer is: Nowhere in the example, but down below in the actual source code. My mistake. My grasp of OO perl and of CGI are, um, weak enough to cause trouble. Thanks for getting me out of it to complete a rather long piece of code.
      -- Jared

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2022-08-18 10:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?