That is just to show the package skeleton in general. It is not required in this case.
There are situations like when you want to initialize some variables in the start or do some cleanup/deallocation at the end, for such cases you might wanna use BEGIN{} and END{}.
package Constructor_Destructor;
BEGIN{
our $text;
$text = "Hello from BEGIN\n\n";
}
sub subroutine{
print $text;
}
END{
print "DESTROYING...\n";
$text=0;
print "Now \$text is $text\n";
print "Exiting with $?\n"
}
#return 1; #did not return since I am calling from the same package
#Use the package:
Constructor_Destructor::subroutine();
You can also use multiple BEGIN{} and END{} subroutines, the BEGIN{} ones would execute in the order encountered and the END{} ones would execute in the reverse order they were defined in order to match the BEGIN{} subroutines..
Excellence is an Endeavor of Persistence.
Chance Favors a Prepared Mind.
|