elTriberium has asked for the wisdom of the Perl Monks concerning the following question:
I've got a short question about how Perl handles return values.
I've got a subroutine that returns multiple values, but in several cases I only need a subset of these values when calling the subroutine.
My question is: How can I specify which ones I want? Please have a look at this short example:
my $result = get_values(); sub get_values { return (“a”, “b”, “c”); }
In my testing $result always gets the value "c" (I assume because it's the last value). But is this guaranteed? Where is this documented? I didn't find anything at http://perldoc.perl.org/perlsub.html or http://perldoc.perl.org/functions/return.html and also perlmonks' search didn't help me out.
And taking this one step further: How can I get "a" and "c"? I know that I can just use three variables and ignore the second one, but I guess there's a better way to do that.
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Ignore certain return values
by bart (Canon) on Oct 21, 2008 at 01:10 UTC | |
|
Re: Ignore certain return values
by ikegami (Patriarch) on Oct 21, 2008 at 07:41 UTC | |
|
Re: Ignore certain return values
by Cristoforo (Curate) on Oct 21, 2008 at 01:14 UTC | |
|
Re: Ignore certain return values
by GrandFather (Saint) on Oct 21, 2008 at 02:05 UTC | |
|
Re: Ignore certain return values
by andreas1234567 (Vicar) on Oct 21, 2008 at 07:27 UTC | |
|
Re: Ignore certain return values
by repellent (Priest) on Oct 21, 2008 at 03:34 UTC |