in reply to Re^4: Getting a Perl program to close a command it starts when the perl program exits?
in thread Getting a Perl program to close a command it starts when the perl program exits?
Yup, that's exactly it. Even more interesting is the difference between lex and pkg vars:
{ package Pkg; sub new { my ($class, $text) = @_; return bless(\$text, $class); } sub DESTROY { my ($self) = @_; print "DESTROY $$self\n"; } } my $lex = Pkg->new('file scope lex var'); our $pkg = Pkg->new('pkg var'); END { print "END\n" } print("At end of script\n");
At end of script DESTROY file scope lex var END DESTROY pkg var
I don't know if the order is unchanging. I wouldn't count on it. Doing our $pkg2 = \$lex; or sub test { $lex } would change the order, for example.
|
|---|