in reply to multiple packages in one file

You can see if a package exists by checking if its symbol table is defined.

package Foo; $a = 1; package main; print "foo\n" if defined %Foo::; print "bar\n" if defined %Bar::;

Note that the symbol table won't be defined until you put a symbol in it; a mere package declaration doesn't seem to do it.

Replies are listed 'Best First'.
Re^2: multiple package in one file
by jeanluca (Deacon) on Mar 12, 2006 at 11:23 UTC
    So my problems is not solved then, because I need to check if the package exists before I use it ?
    Thnx
    Luca

    update: I see it, it works, but this doesn't seem to work:
    if ( defined %A::B$type ) { }
    Any suggestions ?
      You'll need to use curlies to tell Perl that you want a variable as part of the package name.

      Try %{ 'A::B' . $type . '::' }

      Remember to include the extra '::' on the end.

        Thnx!!!!