Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Context aware functions - best practices?

by Zaxo (Archbishop)
on Jan 14, 2003 at 18:48 UTC ( #226923=note: print w/ replies, xml ) Need Help??


in reply to Context aware functions - best practices?

I think the wantarray solution is fine, and not all that awkward. That's what wantarray is for.

I think I can make a case for scalar foo LIST to return the last element of the result return wantarray ? @arr : $arr[-1];
instead of the first. A comma sequence behaves that way in scalar context, so that is the ordinary precedent competing with array count for behavior in scalar context.

A third possibility is to return a reference to the generated array. Some modules do that, but it is clearly not desired here.

No, I don't think you missed anything.

After Compline,
Zaxo


Comment on Re: Context aware functions - best practices?
Download Code
Replies are listed 'Best First'.
Re^2: Context aware functions - best practices?
by Aristotle (Chancellor) on Jan 14, 2003 at 19:02 UTC
    Thanks for the well thought out response. I hadn't even though about -1, but I accept the argument. "Awkward" was probably the wrong term - really I should have written "verbose" instead. I was just wondering if the same behaviour is possible to achieve in a more concise way.

    Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://226923]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2015-07-08 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls