Perl: How to work with methods with multiple outbound parameters

I've seen this quesion asked in several forms so I thought I'd try to shed some light on how to handle accessing methods with multiple outbound parameters using Perl's SOAP::Lite: Let's take a look at these function prototypes:

  1. void func1(out string param1);
  2. void func2(out string param1, out string [] param2);
  3. string func3(out string param1, out string [] param2);
  4. string[] func4(out string param1, out string [] param2);
  5. string func5(out string[] param1, out string [][] param2);

I know there are more combinations than this but this should cover most of the bases (other object types can take the place of string in these examples). I'll take each of these point by point and note how to access the returned parameters. Keep in mind that SOAP::Lite doesn't distinguish a returned value vs an outbound parameter, it uses the FIRST returned value whether it's the return value or the first outbound parameter. Then it stuffs all subsequent parameters into it's paramsout array.

 

1. void func1(out string param1);

Here we have no return value but a single outbound parameter. Since the outbound parameter is the first returned value, it will be stored in the result.

$soapResponse = $soap->func1();
$param1 = $soapResponse->result; # Scalar value
print "param1 => $param1\n";

 

2. void func2(out string param1, out string[] param2)

This method has no return value but two outbound parameters so param1 will be stored in the result and param2 will be the first element of the paramsout array.

$soapResponse = $soap->func2();
@params = $soapResponse->paramsout;
$param1 = $soapResponse->result; # Scalar value
@param2 = @{@params[0]); # Array
print "param1 => $param1\n";
print "param2 => {";
foreach $val (@param2)
{
 print "$val, ";
}
print "}\n";

 

3. string func3(out string param1, out string [] param2);

This method returns a string as a return value and has 2 outbound parameters. So, the returned value will be in the result and params 1 and 2 will be stored in the paramsout array.

$soapResponse = $soap->func3();
@params = $soapResponse->paramsout;
$retval = $soapResponse->result;
$param1 = @params[0]; # Scalar value
@param2 = @{@params[1]); # Array
print "retval => $retval\n";
print "param1 => $param1\n";
print "param2 => {";
foreach $val (@param2)
{
 print "$val, ";
}
print "}\n";

 

4. string[] func4(out string param1, out string [] param2);

This method is similar to number 2, but it returns an array which will be stored in the result and, again, params 1 and 2 will be sotred in the paramsout array.

$soapResponse = $soap->func4();
@params = $soapResponse->paramsout;
@retval = @{$soapResponse->result};
$param1 = @params[0]; # Scalar value
@param2 = @{@params[1]); # Array
print "retval => {";
foreach $val (@retval)
{
 print "$val, ";
}
print "}\n";
print "param1 => $param1\n";
print "param2 => {";
foreach $val (@param2)
{
 print "$val, ";
}
print "}\n";

 

5. string func5(out string[] param1, out string [][] param2);

Here we've introduced an Array of Arrays as an outbound parameter. the Return value will again be returned in the result with the parameters stored in the paramsout array.

$soapResponse = $soap->func5();
@params = $soapResponse->paramsout;
$retval = @{$soapResponse->result};
@param1 = @{@params[0]}; # Array
@param2 = @{@params[1]); # Array of Array
print "retval => $retval\n";
print "param1 => {";
foreach $val (@param1)
{
 print "$val, ";
}
print "}\n";
print "param2 => {\n";
for $i ( 0 .. $#param2 )
{
 print " {";
 for $j ( 0 .. $#{$param2[$i]} )
 {
 print "$param2[$i][$j], "; 
 }
 print "}\n";
}
print "}\n";

You could have used the foreach statement for the array of array but this just shows another way to access the data by index.

-Joe

References

SOAP::Lite
SOAP::Lite Perldocs
Manipulating Arrays of Arrays in perl

Published Nov 15, 2004
Version 1.0

Was this article helpful?