in reply to How can I tell if a function has been forward declared but not yet defined?

The scalar $hello doesn't exist. The subrouine &hello exists.
sub hello; $fn = \&hello; # ...

Alternately:

sub hello; *fn = *hello; # ...

But, either way, your check of $::{'hello'} will fail.

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re^2: How can I tell if a function has been forward declared but not yet defined?
by mab (Acolyte) on Mar 30, 2005 at 20:31 UTC
    %:: is the namespace for the main package and what I'm doing with $::{'hello'} is to get the glob of things pointed at by the name 'hello.' For example, do this and you'll see what I mean:
    sub hello { }; # declared and defined *fn = $::{'hello'}; print "declared\n" if *fn{CODE}; print "defined\n" if defined &fn;
    So I know the technique works - I just need a way to differentiate functions that are only forward declared from ones that are actually defined.
Re^2: How can I tell if a function has been forward declared but not yet defined?
by ihb (Deacon) on Mar 30, 2005 at 21:36 UTC

    The subroutine &hello doesn't exist. In fact $::{hello} is &hello's prototype (as a plain string). There's no CV or CV-ish value around yet--just a plain string being the prototype. When you do *hello, \&hello or $hello you create the glob at comile-time and so $::{hello} returns a glob. This means that

    sub hello; *fh = $::{hello}; *hello;
    works. See Re^3: Grabbing Variable Names for an elaboration.

    ihb

    See perltoc if you don't know which perldoc to read!

Re^2: How can I tell if a function has been forward declared but not yet defined?
by mab (Acolyte) on Mar 30, 2005 at 20:59 UTC
    Hey, I see what you're saying now. Sorry for being slow. I am still curious why the namespace approach doesn't work but thanks for this suggestion.