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

Can I assign a variable to a cgi or perl program and use it in another program? Like:

$prog_test="cgi-bin/test.pl"; print $prog_test;

Replies are listed 'Best First'.
Re: CGI Question
by kabel (Chaplain) on Sep 18, 2002 at 16:17 UTC
    here another guess: perhaps you want to get the output of "cgi-bin/test.pl" as if a user pressed a submit button? then check out this tuturial on lwp::simple.
Re: CGI Question
by zigdon (Deacon) on Sep 18, 2002 at 15:49 UTC
    I'm guessing you're trying to capture the output of one program and print it. you can do it with backticks:
    $output=`cgi-bin/test.pl`;
    which will capture the STDOUT of the test.pl, and put it in the variable $output. Another option is to use system:
    system("cgi-bin/test.pl");
    which will run the program, passing it the current processe's STDOUT and STDERR.

    -- Dan

Re: CGI Question
by sch (Pilgrim) on Sep 18, 2002 at 15:37 UTC

    Well, that will print "cgi-bin/test.pl" to STDOUT but I guess that's not what you want it to do.

    What exactly is it your trying to do with 'test.pl' - capture it's output, just execute it, or something else?

Re: CGI Question
by Abstraction (Friar) on Sep 18, 2002 at 15:48 UTC
    Or if you want the output of that program to be in $prog_test try a

    $prog_test = `perl cgi-bin/test.pl`;

    You my need to modify the path to the script though.
Re: CGI Question
by Flexx (Pilgrim) on Sep 18, 2002 at 17:01 UTC