Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of nicholas (3034)

Tuesday February 16, 2010
01:03 PM

don't do this

[ #40186 ]

It's just occurred to me that it might be possible to goto \&sub_ref out of a BEGIN block. After all, they're really subroutines at heart. So, does it work?

$ cat
#!perl -w
use strict;

sub sick {
    warn "Yuck!";

    goto \&sick;

$ perl
Yuck! at line 5.

Yep. Sure does.

Don't do this.

This is where someone points me at prior art from 10 years ago. There is, after all, nothing new under the sun.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I don't see why one shouldn't be allowed to do this, as it's not really different from plain calling

    BEGIN {
         &sick;   # or sick();

    As part of the source hasn't been compiled (or parsed) yet, you can only jump — or call — backwards.

    • goto &sub doesn't return to its previous callframe. I'm not quite sure how that pans out during compilation. I think that's part of what's worrying Nicholas. :)