Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

subroutine help

by Anonymous Monk
on Jun 28, 2003 at 17:13 UTC ( [id://269908]=perlquestion: print w/replies, xml ) Need Help??

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

Hello everyone, I need to know how i can call a cgi within a cgi using a subroutine like for eq if I have a main cgi which has a subroutine .. and when that subroutine is called it kicks of anohter cgi script and passes a variable to that cgi as well

Replies are listed 'Best First'.
Re: subroutine help
by gjb (Vicar) on Jun 28, 2003 at 17:26 UTC

    Why should it be an CGI? Can't you get away with simply isolating the code that is common to both CGI scripts into one (or more) subroutine(s) in a module that can be called by both scripts?

    Just my 2 cents, -gjb-

      In addition to gjb's comments, if you are worried about requring too much 'stuff' that may not be needed during any one run, you could eval your commands and build your require/use list accordingly:
      if($command = 'getuser') { eval { use MyCode::Users; }; getuser(); }

      That way if you break up your code into multiple scripts and require them (as per gjb's comments), you are still only loading that which you need, dynamically. If you have a lot of subs and a lot of 'commands', this can require some precise forethought, but a little design could save you lots of resources in the long run.
Re: subroutine help
by rruiz (Monk) on Jun 28, 2003 at 21:23 UTC

    If you can install other modules, you may want to take a look at this node that explains the use of the CGI::Application module.

    That way you may take all of your current CGI scripts and pack them in run modes of your main C::A module.

    God bless you
    rruiz

    Update: Corrected link format error found by VSarkiss, thanks

Re: subroutine help
by tcf22 (Priest) on Jun 28, 2003 at 18:55 UTC
    You could probably just require the other cgi script. This will run the other cgi script, then return to the main cgi.

    It looks like there is probably a better way to do what you want. gjb's idea looks like a good way to go.
Re: subroutine help
by rdfield (Priest) on Jun 29, 2003 at 07:48 UTC
    Probably best to encapsulate the required subroutine in a module and use it. If you mean that a certain user action requires two completely seperate CGI transactions you could open a sub window, or sub frame at the client end, or do something whizzy like using a mod_perl handler to generate multiple apache sub requests at the server.

    rdfield

Log In?
Username:
Password:

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

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

    No recent polls found