How do I return multiple values from a Perl function call?
Sample code
my ($value1, $value2, $value3) = getValues(@parts)
sub getValues
{
foreach(@_)
{
$_ =~ m{/test1_name (.*) test2_name (.*) test3_name (.*)/};
$test1_value = $1;
$test2_value = $2;
$test3_value = $3;
}
}
This code is not working.
You don’t need to put it in the foreach loop if you’re just trying to get $1, $2, $3. The
my $str = shift @_;basically says “set the variable str to the first item in the values passed into this sub”.Also, you’re passing in an array. I did a shift because that takes the first value from the array (which I’m assuming is the string you would like to parse). If you’re trying to do something different, update your question and I’ll update my answer.