Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Control Flow - Multiple returns or nested conditionals

by moritz (Cardinal)
on Oct 07, 2010 at 16:17 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-19 15:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found