in reply to goto with anonymous subs

I don't see a gain here for goto sub { ... } over do { ...; return }. You still have the same size call-stack. I think I'd mark this down as being clever for clever's sake.

Now, if you decided to implement continuation passing style with this:

sub cool { my $return = pop; # get cps value my $p1 = shift; my $p2 = shift; ... ... if ($condition) { @_ = ($new, $arg, $new_return); goto &$return; } }
Then I might be impressed.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: goto with anonymous subs
by ysth (Canon) on Sep 12, 2005 at 23:38 UTC
    I'm not sure why you bring up call-stack size. Nothing in the OP leads me to think this is an attempt at optimization.

    The advantage over the do { ;return} form would be not having to have the return. This has three aspects: not having to type it in the first place, not having to read through it in the code, and not having to deal with what can be a debugging hassle of accidentally leaving it out.

    Looks to much like "GOSUB" for my tastes, though.

Re^2: goto with anonymous subs
by kappa (Chaplain) on Sep 12, 2005 at 16:27 UTC
    It's even worse if we consider call stack. This trick clutters it with anonymous entry and therefore interferes with debugging. The only (arguable) gain is (a little) shorter code. I understand this.
    --kap
A reply falls below the community's threshold of quality. You may see it by logging in.