Re: goto return ?



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;

It's not nice having invisible control flow in programs.

You could consider using the -P qualifier on Perl, which will stuff your Perl program
through the C preprocessor if you have one: this would let you turn it into a macro. But
that's also an unpleasant thing to do and is discouraged in the documentation. I think
I might prefer it to hiding returns though.

Rob
.



Relevant Pages

  • 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)
  • Object reference
    ... I was under the assumption that in order to use a object reference I ... should bless its referent - the program below outlines this: ... sub create_logger ... tried to apply C pointer magic to a Perl program. ...
    (comp.lang.perl.misc)
  • Re: OT: Anybody using Xemacs to edit Perl Code?
    ... correctly switches on CPerl mode automatically. ... how a Perl program should be laid out: ... sub myfunc ...
    (comp.lang.perl.misc)
  • Re: goto return ?
    ... Rob Dixon wrote: ... sub do_one_then_two { ... basically I want to override return to log and carp first, ... This will work but if log_error ever fails then it will not execute return. ...
    (perl.beginners)
  • New to CGI.pm
    ... I've written a perl program to quiz myself using a simple text file as ... Input file: ... sub process_test ...
    (perl.beginners)