Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 exploiting the Monastery: (4)
As of 2014-12-29 04:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls