Re: goto return ?



Rob Dixon wrote:
JupiterHost.Net wrote:

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.

I want to be able to:

log_error_and_return($error, @return) if $whatever;

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.

I would make do with

log_error($error), return(@return) if $whatever;


(log_error($error) && return(@return)) if $whatever:
This will work but if log_error ever fails then it will not execute return(@return). perhaps I don't understand your code.
.



Relevant Pages

  • Re: Subroutine interaction
    ... Rob Dixon wrote: ... >sub read_index { ... >a single hash. ... % author_headlines contains the same keys and the author's name with an anchor for the respective link in %author_indexlines as its value ...
    (perl.beginners)
  • Re: [Q] How to eval an EXPR once and make it stick
    ... On Jan 27, Rob Dixon said: ... > sub print_lines { ...
    (perl.beginners)
  • Re: goto return ?
    ... sub do_one_then_two { ... basically I want to override return to log and carp first, ... You could consider using the -P qualifier on Perl, which will stuff your Perl program ... that's also an unpleasant thing to do and is discouraged in the documentation. ...
    (perl.beginners)
  • Re: goto return ?
    ... sub do_one_then_two { ... basically I want to override return to log and carp first, ... I'm not sure if glueing together such different things as handling error ...
    (perl.beginners)