Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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,

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?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2020-02-28 14:30 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (123 votes). Check out past polls.