More symbol table weirdness

Beaves at Beaves at
Thu Feb 10 12:24:32 CST 2000

In a message dated 2/10/00 10:31:20 AM US Mountain Standard Time, 
doug.miles at writes:

<<   # Make XML_ObjTree::* inherit from XML_ObjTree.
   my $package_declaration = <<"EOD";
 package XML_ObjTree::$package;
 \@ISA = ('XML_ObjTree');
   eval $package_declaration;

I think I mentioned this in a previous post, but this eval is unecessary.  
You just have to declare at least one variable in the package and that 
package springs into existence.  And, it doesn't matter what the current 
package is.  So the above code could be reduced to one line with no eval.

# package is the current package.
@{"XML_ObjTree::$package\::ISA"}  = ('XML_ObjTree');

and the package XML_ObjTree::$package will be created.  Note, you have to 
escape the first colon before the 'ISA'.  If you don't, then you'll be 
interpolating the variable $ISA in the package 'package' which is not what 
you want in this case.

If someone doesn't quite get this stuff, post your questions. Since I started 
understanding a bit about Perl packages and symbol tables, I've found the 
above technique and stuff similar to it to be VERY useful.  I think it should 
be in everyone's Bag o' Tricks.


More information about the Phoenix-pm mailing list