Here is my issue with handling argument Perl. I need to pass Perl argument argument to a http request (Webservice) whatever Argument given to the perl file.
perl wsgrep.pl -name=john -weight -employeeid -cardtype=physical
In the wsgrep.pl file, i need to pass the above arguments to http post params.
like below,
http://example.com/query?name=john&weight&employeeid&cardtype=physical.
I am using LWP Package for this url to get response.
Is there any good approach to do this?
Updated: Inside the wsgrep.pl
my ( %args, %config );
my $ws_url =
"http://example.com/query";
my $browser = LWP::UserAgent->new;
# Currently i have hard-coded the post param arguments. But it should dynamic based on the file arguments.
my $response = $browser->post(
$ws_url,
[
'name' => 'john',
'cardtype' => 'physical'
],
);
if ( $response->is_success ) {
print $response->content;
}
else {
print "Failed to query webservice";
return 0;
}
I need to construct post parameter part from the given arguments.
[
'name' => 'john',
'cardtype' => 'physical'
],