How can I resolve this case of “Useless use of a variable in a void context”?
For example:
my $err = $soap_response->code, " ", $soap_response->string, "\n";
return $err;
I get warnings like “Useless use of a variable in a void context”? Why? How can I resolve it?
In case you want to concatenate the arguments, use the
"."operator orjoin:Next is why Perl gives you warnings.
You’re assigning to a scalar variable
$err, and the right-hand side of the assignment is evaluated in scalar context.Binary “
,” is the comma operator. In scalar context it evaluates its left argument in void context, throws that value away, then evaluates its right argument in scalar context and returns that value.Evaluating a variable or a constant and throwing that value away is useless. And perl warns you about this.
FYI: Another possible issue with your code:
The assignment has higher precedence so that is:
See Perl operators and precedence and the Comma operator for more information.