in reply to flavors of "defined"

You need to tread carefully around a couple of issues:

The following avoids the autovivication issue, by starting in the root symbol table (%main::) and proceeding towards the full name:

sub edef { my ($symbol) = @_ ; no strict 'refs' ; my @path = split('::', $symbol) ; my $name = pop @path ; if (@path == 0) { @path = split('::', (caller)[0]) ; # use caller's package if no +ne given } ; if (($path[0] eq '') || ($path[0] eq 'main')) { shift @path ; # '::' => 'main::' and we start at 'main::' any +way } ; my $r_table = \%main:: ; foreach my $part (@path) { $part .= '::' ; if (!exists($r_table->{$part})) { return 0 ; } ; $r_table = $r_table->{$part} ; } ; if (!exists($r_table->{$name})) { return 0 ; } ; return defined(${$symbol}) + 2 ; } ;
this takes the full name of a symbol (e.g. 'foo::bar::cantona')returns 0 if the symbol table doesn't exist, or no symbol of the given name exists in the symbol table. It returns 2 if the name exists, but 3 if the name exists and the related scalar value is defined.

Note that if (say) @foo::bar::cantona exists, then 2 is returned if $foo::bar::cantona does not exist, and also if it exists but is undef. I know of no way around this ambiguity.