in reply to exists *{$glob} ? (+)

Is this what you mean?

*TGlob; # Create a typeglob named 'TGlob'. print "It's there!\n" if exists $::{'TGlob'}; __OUTPUT__ It's there!

Update: Just to clarify.... Typeglobs are the containers for Perl's package global variables. Really they're symbol entries in a particular package's symbol table hash. Package main's symbol table is accessed via %::, or %main::. I'm just checking the global symbol table to see if an entry exists for a particular symbol. If it exists, you've got a typeglob.


Dave

Replies are listed 'Best First'.
Re^2: exists *{$glob} ? (+)
by broquaint (Abbot) on Sep 09, 2004 at 08:20 UTC
    Further that to that you should also check for glob-ness since non-globs can live in symbol tables e.g
    use strict; sub exists_glob { my $tbl = \%main::; $tbl = $tbl->{"$_\::"} for split '::', scalar caller; return exists $tbl->{$_[0]} && 'GLOB' eq ref \$tbl->{$_}; } $main::{foo} = "I'm a string"; *bar = \"I'm in a glob"; printf "%s is%s a glob\n", $_, (exists_glob($_) ? '' : "n't") for qw/ foo bar /; __output__ foo isn't a glob bar is a glob
    HTH

    _________
    broquaint

      Replacing the $main::{foo} line with sub foo (I am a string); gives a more realistic example.