in reply to eval and goto: no worky?

Perl tells you "Can't goto subroutine from an eval-block".

You ask Perl to catch errors, then you ask Perl to replace the currently running function with another, but it can't continue to catch errors if it's no longer running. Given conflicting instructions, Perl lets you know you have something to fix.

Update: Substituted the explanation with a much clearer version.

Replies are listed 'Best First'.
Re^2: eval and goto: no worky?
by saintmike (Vicar) on Nov 09, 2010 at 23:02 UTC
    Interesting, I didn't see a warning with warnings and strict on. Did you find that in the documentation?
      foo( "a" ); sub foo { eval { goto &foo2; } or warn $@; } sub foo2 { print "foo2 called with @_\n"; } __END__ Can't goto subroutine from an eval-block at - line 4.
      It's not a warning, it's a fatal error. You successfully caught the error and subsequently ignored it. An Anonymous Monk shows how you could actually look at the error you are hiding.