Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Elegant way to return true or nothing from a subroutine?

by pdcawley (Hermit)
on Oct 10, 2006 at 11:00 UTC ( #577369=note: print w/replies, xml ) Need Help??


in reply to Elegant way to return true or nothing from a subroutine?

How about:
sub foo { shift->{some_obj}->some_method && 1 || return }
Personally I think your attachment to requiring that all your true values be 1 is vaguely silly. A better solution would seem to be:
sub foo { shift->{some_obj}->some_method || return }
Wah! Guess who's been programming in ruby recently. I initially wrote those as sub foo; ...; end

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://577369]
help
Chatterbox?
[LanX]: Moon not Mars
Corion updates his location info to "I'm needed everywhere"
[choroba]: needed everywhere, available rarely

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (17)
As of 2017-03-27 15:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.