Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: Re: Re: Context aware functions - best practices?

by sauoq (Abbot)
on Jan 15, 2003 at 22:56 UTC ( #227264=note: print w/ replies, xml ) Need Help??


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

That's obviously a list-context function, and you don't expect it to do anything useful at all in scalar context.

You make a good point here. Some functions just shouldn't be expected to do anything useful in scalar context. A nice idiom for writing such functions is to start them with wantarray or return undef.

-sauoq
"My two cents aren't worth a dime.";


Comment on Re: Re: Re: Re: Context aware functions - best practices?
Download Code
Replies are listed 'Best First'.
Re^5: Context aware functions - best practices?
by Aristotle (Chancellor) on Jan 15, 2003 at 23:55 UTC
    Or maybe just return unless wantarray; because return is smart enough to provide undef by itself in scalar context. :)

    Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (11)
As of 2015-07-31 07:27 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 (275 votes), past polls