Stories
Slash Boxes
Comments
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 sick.pl
#!perl -w
use strict;

sub sick {
    warn "Yuck!";
}

BEGIN {
    goto \&sick;
}

__END__
$ perl sick.pl
Yuck! at sick.pl 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.
 Full
 Abbreviated
 Hidden
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. :)