Re: goto return ?
- From: info@xxxxxxxxxxxx (D. Bolliger)
- Date: Mon, 27 Nov 2006 23:07:36 +0100
JupiterHost.Net am Montag, 27. November 2006 21:37:
What about doing this?
return if do_one_then_two($whatever);
...
sub do_one_then_two {
my $what = $_[0];
if ($what) {
one();
two();
return 1;
}
return 0;
}
Thanks, I'm not looking for how to handle a condition necessarily.
Dear JupiterHost.Net
I want to be able to:
log_error_and_return($error, @return) if $whatever;
That's what you want? And it should return @return?
instead of
if($whatever) {
log_error();
carp $error;
return @return;
}
basically I want to override return to log and carp first, every time
its called.
Ok, another try (I would not use it myself):
sub my_return {
my ($error, $return_data)=@_;
# do what boss wishes today
return $return_data;
}
# unconditional usage:
#
return my_return($error, $return_data);
# conditional usage:
#
return my_return($error, $return_data) if $whatever;
foo() unless returned_above();
========
I think you have to explicitly use the return. Otherwise, Tom Phoenix's notes
apply.
It's a really good thing to see 'return' at exactly the place where the code
does (or can) return to the caller.
========
I'm not sure if glueing together such different things as handling error
messages and returning application data is a good thing...
Do you now of the possibility to override $SIG{__WARN__}? This would allow to
keep recommended and usual coding style.
Dani
.
- References:
- goto return ?
- From: JupiterHost.Net
- Re: goto return ?
- From: Mumia W.
- Re: goto return ?
- From: JupiterHost.Net
- goto return ?
- Prev by Date: Re: goto return ?
- Next by Date: Perl DBI Oracle: Multiple statements
- Previous by thread: Re: goto return ?
- Next by thread: Re: goto return ?
- Index(es):
Relevant Pages
|