Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: On Scalar Context

by fletcher_the_dog (Friar)
on Apr 23, 2004 at 15:40 UTC ( [id://347659]=note: print w/replies, xml ) Need Help??


in reply to Re: On Scalar Context
in thread On Scalar Context

I agree with davido, I don't think it makes sense to necessarily return the same thing every time in scalar context. It wouldn't make sense to have the "wantarray" function at all if scalar context always returned the length of the list. A sub-routine could just always return a list and if it was in scalar context the list length would be given. But the usefullness of "wantarray" is that you can return something different if you know you are in scalar context and not list context.

Replies are listed 'Best First'.
Re: Re: Re: On Scalar Context
by flyingmoose (Priest) on Apr 23, 2004 at 18:41 UTC
    From a evil-software design overlord perspective, I don't believe in wantarray being a good idea at all -- but you are probably glad that I'm not in charge. Technically, a function could do something entirely different based on context, not just in return type, and should it really be able to do that...

    Perl says do whatever you want, but in the general case, that's asking for trouble. Feel free to disagree, that's fine, but there are many aspects about Perl that make it sloppy. Sometimes these are the same reasons that make it flexible and cool, but sometimes not.

    So if people can argue Perl OO is ugly (most would agree), I can argue that wantarray is ugly... Never mind that wantarray seems to imply a true/false value from a design standpoint but actually returns undef, true, or false -- it's a three way statement.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-25 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found