Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
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
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 about the Monastery: (14)
As of 2014-12-19 09:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (77 votes), past polls