codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  From variable to function?  mengrie at 14:18 on Wednesday, January 23, 2008
 

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 http://www.soaplite.com/Demo -p http://services.soaplite.com/hibye.cgi -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;

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

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
# http://guide.soaplite.com/#writing%20a%20client
# http://www.robertprice.co.uk/robblo...With_Perl.shtml
# 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} : "http://localhost/";
my $proxy = defined($options{p}) ? $options{p} : "http://localhost/";
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 http://www.soaplite.com/Demo -p http://services.soaplite.com/hibye.cgi -m hi()

Thx in advance for anyone helping me out here

Regards

Marc

  Re: From variable to function?  mimir at 15:45 on Wednesday, January 23, 2008
 

I take it you want to call a function which is named... whatever the content of a specific variable is.


if so then try:

my $result = $soap->&$method;



  Re: From variable to function?  mengrie at 18:27 on Wednesday, January 23, 2008
 

Tried that already before but I get the error message

syntax error at SOAP-Ping.pl line 41, near "->&"

:-((








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: How to open a MS Word document from Javascript
•  Re: Help: Trouble with z-Index and SELECT lists
•  Re: From variable to function?
•  Re: put entire hash into a data structure.
•  302 Error, on a Web Bot
•  A bracket with both !? and ?:
•  Re: Learning Perl
•  Re: adding a single \ to text
•  Re: problem with STDIN func.


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008