in reply to Re^4: 'return:' instead of 'return'
in thread 'return:' instead of 'return'

Yes, there is no difference and why should there be any? return exists because you might want to leave the subroutine in the middle instead of at the end or leave from more than one location in the subroutine. And it exists to make it explicit what value is returned, it makes the program easier to read and less errorprone. If you have Damian Conways book 'Perl Best Pratices' at hand, it gives an example why explicit returning is better style, in section 'Implicit Returns'

Replies are listed 'Best First'.
Re^6: 'return:' instead of 'return'
by Boldra (Curate) on Jun 12, 2009 at 11:58 UTC
    Yes, there is no difference and why should there be any?
    I don't know, maybe you could use it to force other Best Practices, eg:
    sub close_all { my $self = shift; $success = 1; foreach( $self->files ) { $success = $_->close && $success } return $success or die("You must check the return value of close_all +"); }
    Where return would only evaluate to true if the calling program read the value of the call.

    (Yes, I know you can already do this with the cpan module Want).


    - Boldra

      Leaving aside Corions excellent answer why the built-in return never returns a value, if it did I would expect it to return the same value it returns to the caller. I.e. print return 3; would print 3. Returning a boolean value would only make sense if there were a chance return might fail or return might not always return from the subroutine. Then true or false would inform about the success of the operation.

      You always have the option to write your own function 'myspecialreturn()' that returns only on some conditions (like the result of Want for example).