in reply to How to convert a symbolic reference to a hard reference

I see your question has been answered directly by a few other fine Monks, but I thought I might add something. If you'd like to get a coderef without using eval, you can use can. For example:

sub foo { print "Foo!\n"; } my $pkg = "main"; my $sub = "foo"; my $cr = $pkg->can($sub) or die "Can't find '$sub' in package '$pkg'\n"; $cr->();

Replies are listed 'Best First'.
Re: Re: How to convert a symbolic reference to a hard reference
by ysth (Canon) on Nov 06, 2003 at 03:24 UTC
    Very nice, thanks. You don't even have to split the package off:
    $sub = "X::foo"; $cr = main::->can($sub);
    You can just use any existing package name. (I say main:: instead of main-> in case there is a &main sub.)

    If you are downvoting this for other than lack of interest, thanks for sending me a message or reply to let me know why so I can do better (or just stay quiet) next time.