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

Ok. I think I need to clarify some issues here. :o)
The setup is like this:
All the files are on the same server and in the same directory.
The file to be executed is 1.pl and it requires a querystring '?' with a filename.
1.pl reads the content of the file specified in the argument/querystring, processes it and outputs a html-response (its a menu-system).
I want to execute the 1.pl file (with the querystring/argument) from another file, 2.pl and save the response to a textfile.
Sorry for my ignorance, I am a ASP-programmer and dont know too much about perl.

Replies are listed 'Best First'.
Re: Clarifikation of Newbie question
by Malkavian (Friar) on Oct 25, 2000 at 18:27 UTC
    What you really want to do is read the docs on CGI.pm.(perldoc -f CGI)
    This explains how to get the info out of a query string, and what to do with it.
    perldoc -f open explains how to open a file for output.
    The rest, as they say, is a matter of piecing it together into a program.

    Malk
    *I lost my .sig. Do you have a spare?*
      I know how to list the the content of 1.pl and I know how to list the content of filename.txt (using the querystring).

      The problem is, I need the result of the execution of those two files combined.
      http://www.someserver.com/cgi-bin/1.pl?filename.txt
      The above line generates a menusystem, using data from filename.txt and putting it into a menusystem 1.pl
      So what I need is the result of the execution put into another file.
        Ok, I apologise if I'm being overly dense, but I don't get what you're actually asking.
        Executing the CGI as above would enable 1.pl to grab the filename, and use it to it's own nefarious ends.
        If this file contains data for a menuing system, then the rest is merely generic programming.
        If you need the data from the execution of 1.pl placed in another file, you can use string manipulation to add a prefix/other suffix to use filenam.txt as your root, so you know what the final file relates to.
        If it's just a generic file, think of a name and open(F,">/blah/otherfile");print F "other data";close F;
        Again, apologies if I've missed the point entirely, but this is simply where reading your specification of the problem leads my thinking.

        Malk
        *I lost my .sig. Do you have a spare?*
Re: Clarifikation of Newbie question
by Trimbach (Curate) on Oct 25, 2000 at 21:12 UTC
    I think some of the confusion here has to do with the way both programs are to be executed. Here's what I think you want, and here's how to do it. I'm assuming that the 1.pl program (a CGI) is no available to you to modify (or this whole thing would be alot easier :-D) So, you want 2.pl to execute 1.pl with a querystring. Piece of cake.
    use LWP::Simple; $escaped_querystring = "something"; $output = get ("http://someurl/cgi-bin/1.pl?$escaped_querystring");
    After this is executed $output will contain whatever 1.pl sent back to the webserver for output, i.e., if it sent back an HTML page, $output will contain the HTML page. You can write 2.pl to construct your querystring to be anything you want, just make sure it's escaped of all the nasty little HTTP characters and such. You can use URI::Escape to do that.

    Hope this helps.

    Gary Blackburn
    Trained Killer

      THANK YOU!

      This is what I was looking for!
      :o)