programming-examples/perl/Class/Destructors and Garbage Collection.pl
2019-11-15 12:59:38 +01:00

31 lines
575 B
Perl

#Employee.pm
package Employee;
sub new{
my $class = shift;
$ref={};
bless($ref, $class);
return $ref;
}
sub DESTROY{
my $self = shift;
print "Employee $self->{Name} is being destroyed.\n";
}
1;
#!/usr/bin/perl
use Employee;
my $emp1 = Employee->new;
{ my $emp2 = Employee->new;
$emp2->{"Name"}="Tom";
print "$emp2->{'Name'}\n";
}
my $emp3 = Employee->new;
$emp1->{"Name"}="Dan";
$emp3->{"Name"}="Tom";
print "$emp1->{'Name'}\n";
print "$emp3->{'Name'}\n";