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

Hello

This is probably an easy answer, but it currently eludes me. I have an html form that is genreated by a perl script. When the user hits submit, it calls a different perl script.

But what I would like to know is, if it's possible for a perl script to call another perl script and have it (the called script) 'take over' and serve up the html.

I know about calling a sub-routines from an external file, but what I want is for a script to start another script and have it finish the processing.

Perhaps I'm making my life more difficult than it has to and just incorporate everything in one script? Well I figured it couldn't hurt to ask!


Thanks for your time and help!
Alex

Replies are listed 'Best First'.
Re: Referring to another perl script....
by hardburn (Abbot) on May 06, 2003 at 16:02 UTC

    Sure, its possible, but is generally more complex than it's worth. You could try:

    # %params defined elsewhere, holding CGI input data open(OUT, '|-', '/path/to/cgi') or die $!; foreach my $key (keys %params) { print OUT "$key=$params{$key}\n"; } close(OUT);

    It's generally easier to load the second CGI's subroutines into a module and use them from there. The example above will work in one simple (though common) case and fail in a thousand others.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    Note: All code is untested, unless otherwise stated

      HardBurn

      Thanks for your info. But being generally new to perl, I'm a little confused with your code. I know you opened a filehandle 'OUT' to the script I want to use. But what does the '|-' do? Is it some kind of pipe redirection?

      Another thing :) what exactly is a module? Is it like an external sub-routine file, that has functions pre-defined for common uses... like CGI.pm?

      Other than that I understand everything else you posted.


      Thanks!
      Alex
Re: Referring to another perl script....
by LordWeber (Monk) on May 06, 2003 at 16:07 UTC
        LordWeber

        Thanks for your post. Here's my question though, what exactly do you mean by:

        system('perlscriptpath',@arguments)

        Thanks!
        Alex
          First you gotta ask you self, what's that look like? I'd assume it's some perl code. So that'd make system a function. Where does this function come from? Say you don't know, you gotta ask yourself, is it a built-in? And then check `perldoc -f system', and then read the documentation. I hope that clears it up for you. You'll also wanna read this, cause it points out various sources of documentation.


          MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
          I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
          ** The Third rule of perl club is a statement of fact: pod is sexy.

    Re: Referring to another perl script....
    by dstotten (Novice) on May 06, 2003 at 17:26 UTC
      Maybe I am mis-reading what you are trying to do, but are you trying to have one CGI script call another perl script, and have the first CGI script finish while the other perl script does all of the number crunching?

      In other words, foo.cgi starts bar.pl, and foo.cgi finishes right away, but bar.pl still continues doing stuff?
        DStotten

        Ummm.... yeah :) Why is that not possible?

        By the way, what's with all this 'foo' stuff. I find constant references to it within the perl documentation and throuhout many other places as well. Is it some kind of fond reference to something?

        Just curious.

        Thanks
        Alex