A
Alex Hart
I thought that these are equivalent:
use Symbol;
my $fh = gensym;
and
local *FH;
my $fh = \*FH;
But the following code doesn't treat them the same.
#!/usr/bin/perl -w
use Symbol;
use strict;
my $file = Test_close->new("test");
package Test_close;
{
my $testdiename;
sub new {
my ($class, $name) = @_;
print ("Test_close on $name\n");
$testdiename=$name;
local *TMP;
my $tmp = \*TMP; # THIS LINE AND THE NEXT ARE THE TEST
# my $tmp = Symbol::gensym();
bless $tmp, $class;
}
sub DESTROY {
print "\n\n$testdiename died\n\n";
}
}
__END__
When I run this using gensym, it does what I expect, but when I create
the anonymous glob myself, the DESTROY function is not called.
Can someone explain what's the difference and why the object is not
destroyed.
Thanks.
- Alex Hart
use Symbol;
my $fh = gensym;
and
local *FH;
my $fh = \*FH;
But the following code doesn't treat them the same.
#!/usr/bin/perl -w
use Symbol;
use strict;
my $file = Test_close->new("test");
package Test_close;
{
my $testdiename;
sub new {
my ($class, $name) = @_;
print ("Test_close on $name\n");
$testdiename=$name;
local *TMP;
my $tmp = \*TMP; # THIS LINE AND THE NEXT ARE THE TEST
# my $tmp = Symbol::gensym();
bless $tmp, $class;
}
sub DESTROY {
print "\n\n$testdiename died\n\n";
}
}
__END__
When I run this using gensym, it does what I expect, but when I create
the anonymous glob myself, the DESTROY function is not called.
Can someone explain what's the difference and why the object is not
destroyed.
Thanks.
- Alex Hart