Re: goto return ?



On 11/24/2006 05:37 PM, JupiterHost.Net wrote:


Tom Phoenix wrote:
On 11/24/06, JupiterHost.Net <mlists@xxxxxxxxxxxxxxx> wrote:

The trick is I can't seem to goto() return in
do_some_stuff_and_return(), I'm sure since its so deep down...


Are you saying that you want a subroutine that can make the subroutine
that called *it* return? I'm not sure that that would make sense; and
it's not something that anybody's style guide recommends for normal
programming, since it leads to some ambiguous situations.

There's probably a better way to structure your algorithm. Or maybe
I've misunderstood your situation. Good luck with it!

Thanks Tom, I'll try to clarify.

In a function I can do this:

# stuff here

if($whatever, @ret) {
one();
two();
goto &CORE::return; # this is pseudo code that does not work but illustrates the idea of the goal
}

# keep going since that function didn't return.

Say you have to do that expect same logic ten times, it'd be nice instead of fifty of the exact same lines to have ten lines by do ing this:

# stuff here

do_one_then_two_then_return_if($whatever);

# keep going since that function didn't return.

Just need to figure you how to get the functionality that:

goto &CORE::return;

feels like it should do assuming I knew how to reference return...


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;
}


Or you could use the (much to complicated for this) Error module.


.



Relevant Pages

  • Re: goto return ?
    ... Tom Phoenix wrote: ... Are you saying that you want a subroutine that can make the subroutine ... since it leads to some ambiguous situations. ...
    (perl.beginners)
  • RE: [Full-Disclosure] Coding securely, was Linux (in)security
    ... > So you're saying I don't need to worry if a file pointer is NULL before ... So I don't need to worry if an argument ... subroutine should NEVER assume that the caller has checked. ...
    (Full-Disclosure)
  • RE: [Full-Disclosure] Coding securely, was Linux (in)security
    ... that is not what I'm saying. ... What I'm saying is that the programmer ... should not *expect* the subroutine to do his error checking for him. ... The problem we have now is everyone is expecting someone *else* to do the ...
    (Full-Disclosure)