Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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


Comment on Re: Elegant way to return true or nothing from a subroutine?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (20)
As of 2015-07-06 18:06 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 (80 votes), past polls