> > NewPackage will then contain all things in TestPackage....
>>
>> Then you can redefined everything in TestPackage without affecting
>> anything in NewPackage.
>
>Actually it will, if you were to delete NewPackage, TestPackage would not
>contain anything. Modifying 'thingys' in TestPackage would modify
>NewPackage.
Actually I investigated this a little more and discovered some
strange things...
If you check out the results, copying the package at the package
level cause scalars to be redefined and subroutines to created as
references. Where as copying the the package at the glob level
caused the the subroutines to be redefined and the scalars to be
references...
I wonder if this is a problem with perl?
Robert Landrum
--- results ---
# perl n.pl 1
NewPackage::x was defined
NewPackage::june was defined
$NewPackage::x was set to 100
$Test::x now contains 100
Now Deleting Test package
Test::x was deleted from the STASH
Test::june was deleted from the STASH
$NewPackage::x was set to 100
$Test::x now contains 100
Now Listing NewPackage
NewPackage::x
NewPackage::june
Now Listing Test
# perl n.pl
NewPackage:: was defined as *{Test::}
$NewPackage::x was set to 100
$Test::x now contains 1
Now Deleting Test package
Test::x was deleted from the STASH
Test::june was deleted from the STASH
$NewPackage::x was set to 100
$Test::x now contains 1
Now Listing NewPackage
Now Listing Test
--- Contents of n.pl ---
#!/usr/bin/perl
package Test;
our $x = 1;
sub june {
}
package main;
if($ARGV[0]) {
for my $name (keys %{Test::}) {
*{"NewPackage::".$name} = *{"Test::".$name};
print "NewPackage::".$name." was defined\n";
}
print "\n";
} else {
*{NewPackage::} = *{Test::};
print "NewPackage:: was defined as \*{Test::}\n";
print "\n";
}
$NewPackage::x = 100;
print "\$NewPackage::x was set to $NewPackage::x\n";
print "\$Test::x now contains $Test::x\n";
print "\n";
print "Now Deleting Test package\n";
for my $name (keys %{Test::}) {
delete $Test::{$name};
print "Test::".$name." was deleted from the STASH\n";
}
print "\n";
print "\$NewPackage::x was set to $NewPackage::x\n";
print "\$Test::x now contains $Test::x\n";
print "\n";
print "Now Listing NewPackage\n";
for my $name (keys %{NewPackage::}) {
print "NewPackage::".$name."\n";
}
print "\n";
print "Now Listing Test\n";
for my $name (keys %{Test::}) {
print "Test::".$name."\n";
}
print "\n";