Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^5: replace use HTTP::Lite to run a perl file that was on another server

by huck (Prior)
on Feb 21, 2017 at 03:27 UTC ( [id://1182393]=note: print w/replies, xml ) Need Help??


in reply to Re^4: replace use HTTP::Lite to run a perl file that was on another server
in thread replace use HTTP::Lite to run a perl file that was on another server

"as a second afterthought, my ($cgi, $CMD) = shift; looks strange. i would have used my ($cgi, $CMD) = @_; instead" Re^2: replace use HTTP::Lite to run a perl file that was on another server

#!/usr/bin/perl -w my $all=get_response('a','b'); sub get_response { my ($cgi, $CMD) = shift; print 'a'.$cgi."\n"; print 'b'.$CMD."\n"; }
Result:
aa Use of uninitialized value $CMD in concatenation (.) or string at x118 +2315.pl line 6. b

is now in the same cgi-bin directorty as the perl script that is calling for that script. replace use HTTP::Lite to run a perl file that was on another server Taking that to mean that the caller was cgi as well i added as an afterthought, that &get_response clobbers %ENV, so you might want to add local %ENV=%ENV; as the first line in sub get_response Re^2: replace use HTTP::Lite to run a perl file that was on another server because i didnt want a clobbered %ENV to mess up some other part of the cgi script.

so probably best is

sub get_response { local %ENV=%ENV; my ($cgi, $query) = @_; ## prepare proper (CGI) environment $ENV{QUERY_STRING} = $query; $ENV{REQUEST_METHOD} = 'GET'; $ENV{GATEWAY_INTERFACE} = 'CGI/1.1'; # add more as needed open(CGI, '-|', $cgi) or die "Can't exec $cgi, $!"; local $/ = undef; my $res = <CGI>; close(CGI) or die "Error running $cgi, $!"; return $res; }
Tho in this case the 3 arg open didnt mean as much since we know that the $cgi parm had no special characters being hardcoded.

well at least my first post had added Using get_response from that node and untested and i did look over the code again and again to make sure it was doing what i thought it was and posted addendums to correct what i thought were weaknesses.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-20 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found