throop has asked for the wisdom of the Perl Monks concerning the following question:
How do I pull out the n'th value when a function returns a list, without using an intermediate array variable? E.g. the following works, but by introducing the clutter of @temp;
but the following attempts don'tuse strict; sub dirs{qw(NORTH SOUTH EAST WEST)} my(@temp) = dirs(); my($horaceGreeleyDir) = $temp[3];
This works, but is looks worse than the original:my($horaceGreeleyDir) = dirs()[3]; my($horaceGreeleyDir) = @{dirs()}[3]; my($horaceGreeleyDir) = ${dirs()}[3]; my($horaceGreeleyDir) =()[3] = dirs();
Suggestions?(undef, undef, undef, my $horaceGreeleyDir) = dirs();
throop
meta-question: on what should I have searched to answer this question myself?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pulling out an element from a function return without using an intermediate list
by ikegami (Patriarch) on Feb 19, 2007 at 21:42 UTC | |
|
Re: Pulling out an element from a function return without using an intermediate list
by rhesa (Vicar) on Feb 19, 2007 at 21:42 UTC | |
|
Re: Pulling out an element from a function return without using an intermediate list
by Joost (Canon) on Feb 19, 2007 at 21:43 UTC | |
by throop (Chaplain) on Feb 19, 2007 at 22:11 UTC | |
by GrandFather (Saint) on Feb 19, 2007 at 22:16 UTC | |
by ikegami (Patriarch) on Feb 19, 2007 at 22:17 UTC | |
by Joost (Canon) on Feb 19, 2007 at 22:36 UTC |