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

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

Replies are listed 'Best First'.
Re^7: 'return:' instead of 'return'
by jethro (Monsignor) on Jun 12, 2009 at 13:34 UTC

    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).