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

Re^5: Context aware functions - best practices?

by LAI (Hermit)
on Jan 15, 2003 at 14:33 UTC ( #227150=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Context aware functions - best practices?
in thread Context aware functions - best practices?

Ugh, that's the worst of both worlds

Hurrah for nauseatingly ugly code...

Anyway, yeah. The return type would definitely have to be the same regardless of the args. Having to test the type every time a sub is called is unacceptable. How does CGI's $calar = $cgi->param() decide which value to return, though (if it's a multivalue parameter)? Is it just the first (or last) one input?

I just RTFM'd and RTFSource'd, and CGI->param() does this:

return unless defined($name) && $self->{$name}; return wantarray ? @{$self->{$name}} : $self->{$name}->[0];

There you have it, I guess. Return the whole array or the first element. I still like Zaxo's idea of returning @rray[-1], though... I guess it depends what sub foo does.


LAI
:eof


Comment on Re^5: Context aware functions - best practices?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (14)
As of 2014-10-24 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (131 votes), past polls