Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Control Flow - Multiple returns or nested conditionals

by moritz (Cardinal)
on Oct 07, 2010 at 16:17 UTC ( #864030=note: print w/replies, xml ) Need Help??


in reply to Control Flow - Multiple returns or nested conditionals

I generally prefer less nesting, and thus direct return. However your example suffers from code duplication for the version that uses return(), though that's not necessary:
sub err { { status => 0, error => shift(@_), external_id => undef); } sub foo { my($self) = @_; my $authentication = $self->authenticate_user(); return err('Authentication Failed') unless defined $authentication; my $profile = $self->get_user_profile(); return err('User is not active') unless $profile->is_active; my($external_id) = $self->find_external_id($profile); if(! defined($external_id)){ $external_id = $self->send_profile_to_partner($profile); } return {status=>1, error=>undef, external_id=>$external_id}; }
Perl 6 - links to (nearly) everything that is Perl 6.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2021-07-27 21:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?