Lyndley has asked for the wisdom of the Perl Monks concerning the following question:
Basically I want to return just one element of an array where the array is actually a return value from a function without having to define a temporary variable.
For example using localtime I might just want to return the hour which could be done using.
my @temp=localtime(time); print $temp[ 2 ]
I've tried different types of syntax but can';t quite seem to figure out the best way, I was hoping something like :
print localtime(time)[ 2 ]
would work. Another example might be the return value from a Win32::ODBC Error call.
print $db->Error[ 1 ]
Which again of course doesn't work!
Could any monks offer insight or give example as to how I would do this.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: array element return syntax
by ikegami (Patriarch) on Mar 29, 2006 at 15:32 UTC | |
by Lyndley (Novice) on Mar 29, 2006 at 15:42 UTC | |
by davorg (Chancellor) on Mar 29, 2006 at 15:50 UTC | |
by ikegami (Patriarch) on Mar 29, 2006 at 15:46 UTC | |
|
Re: array element return syntax
by Rice (Acolyte) on Mar 29, 2006 at 15:40 UTC | |
|
Re: array element return syntax
by kwaping (Priest) on Mar 29, 2006 at 15:42 UTC | |
by merlyn (Sage) on Mar 29, 2006 at 15:56 UTC | |
by kwaping (Priest) on Mar 29, 2006 at 15:57 UTC | |
by ikegami (Patriarch) on Mar 29, 2006 at 15:44 UTC | |
by Lyndley (Novice) on Mar 29, 2006 at 15:53 UTC | |
by duff (Parson) on Mar 29, 2006 at 16:16 UTC |