Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

From variable to function?

Status
Not open for further replies.

mengrie

Technical User
Jan 23, 2008
1
BE
Hello,

I am writing a small Perl program to atest the availbility of a webservice.

So the idea is to call a known method of a known webservice and check the result.

To make the program flexible and to allow me to test several webservices I pass te following params from the command line

SOAP-ping.pl [ -u url ] [ -p proxy ] [ -m method ]

eg: perl SOAP-Ping.pl -u -p -m hi()

I pick up the params using the use Getopt::Std;

and pass them to the SOAP::Lite object.

Passing the URL & proxy is not an issue but the method is causing me a headegde.

As I get the method as a variable (string) I can not pass it to SOAP::Lite as this requires it in a different form.

my $soap = SOAP::Lite
-> uri($url)
-> proxy($proxy);

# this ain't working
my $result = $soap->$method;

# this ain't working
my $result = $soap->&$method;

as it generates an error
syntax error at SOAP-Ping.pl line 41, near "->&"

The code that works is
my $result = $soap->hi();

but thats of course not what I want because method is hard coded.

So my Perl questions is: How can I make this last line variable so I can pass the method via the command line instead of 'hard coded' in de code?

Here is the full version of my test program

#!/usr/bin/perl -w
# # # Usage: SOAP-ping.pl [ -u url ] [ -p proxy ] [ -m method ]

####################################
# Modules #
####################################
use Getopt::Std;
use Time::HiRes qw (time);

use SOAP::Lite;

####################################
# Globals #
####################################

####################################
# Get the parameters from the user #
####################################
%options=();
getopts("u:p:m:",\%options);

my $url = defined($options{u}) ? $options{u} : "my $proxy = defined($options{p}) ? $options{p} : "my $method = defined($options{m}) ? $options{m} : "";

####################################
# Test Connection #
####################################

printf("Url: %s\nProxy %s\nMethod: %s\n",$url, $proxy, $method);

# Calculate the time it takes
my $start = time();

my $soap = SOAP::Lite
-> uri($url)
-> proxy($proxy);

my $result = $soap->hi();

unless ($result->fault)
{
print $result->result(),"\n";
}
else
{
print join ', ',
$result->faultcode,
$result->faultstring;
}

my $soaptime = time() - $start;

printf("%d\n%d\n",$soaptime * 1000, $soaptime * 1000);


To test it:

perl SOAP-Ping.pl -u -p -m hi()

Thx in advance for anyone helping me out here

Regards

Marc
 
check the other forums you posted this same question on.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top