mrd has asked for the wisdom of the Perl Monks concerning the following question:
I'm looking for a shortcut to extract a specific element out of an array without using a temporary variable. The array is returned by a function and I only need a particular element of that.
Since a line of code is worth 2000 lines of plain (gibberish) text (of mine), here is what I do:
Only I want to do it shorter. Something like:@tmp = function($param); $elem = $tmp[5]
which obviously doesn't work.$elem = (function($param))[5]
Thanks,
mrd
PS: I could wrap function() in another function that returns the element I want from a local array. But that's just too much work :)
PPS: I'm sure it's been discussed before but I can't seem to come up with an adequate search expression.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Looking for syntactic shortcut
by merlyn (Sage) on Jul 19, 2005 at 12:52 UTC | |
by mrd (Beadle) on Jul 19, 2005 at 12:55 UTC | |
by Thilosophy (Curate) on Jul 19, 2005 at 12:58 UTC | |
by socketdave (Curate) on Jul 19, 2005 at 13:00 UTC | |
by mrd (Beadle) on Jul 19, 2005 at 13:06 UTC | |
by gellyfish (Monsignor) on Jul 19, 2005 at 13:03 UTC | |
by rev_1318 (Chaplain) on Jul 19, 2005 at 13:01 UTC | |
by virtualsue (Vicar) on Jul 19, 2005 at 13:01 UTC | |
by eyepopslikeamosquito (Archbishop) on Jul 19, 2005 at 13:02 UTC | |
|
Re: Looking for syntactic shortcut
by BrowserUk (Patriarch) on Jul 19, 2005 at 12:52 UTC |