http://qs321.pair.com?node_id=328293

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

I have a URL that I would like to execute. I need variables in the URL to be posted correctly like this:

myperlscript.pl?var1=1&var2=2

I just dont want to redirect.

I so far have tried all of these things:

print qx "myperlscript.pl?var1=1&var2=2"; system("myperlscript.pl?var1=1&var2=2");use my $response =LWP::UserAgent->new->get("myperlscript.pl?var1=1&var2=2" +);

Thanks!!!

20040211 Edit by Corion: Exchanged PRE tags for formatting

Replies are listed 'Best First'.
Re: Dynamicly Execute URL without redirection
by tcf22 (Priest) on Feb 11, 2004 at 16:00 UTC
    You have to specify the whole URL so
    my $response =LWP::UserAgent->new->get("http://www.mydomain.com/myperl +script.pl?var1=1&var2=2");
    should be what you want.

    UPDATE:
    If you just want to run the script, then LWP::UserAgent may be overkill. LWP::Simple will probably do what you want.
    use LWP::Simple; my $data = get("http://www.mydomain.com/myperlscript.pl?var1=1&var2=2" +);

    - Tom

Re: Dynamicly Execute URL without redirection
by valdez (Monsignor) on Feb 11, 2004 at 19:29 UTC

    If you want a correct URL use the URI module to build it, for example:

    $uri = URI->new('http://www.example.com/myperlscript.pl'); $uri->query_form( 'var1' => $var1, 'var2' => $var2 ); $page = get( $uri->as_string );

    HTH, Valerio