Coding Domain

Perl Programming: Samples


Apl.pl
#!/usr/bin/perl -w

use strict;
use diagnostics;
use Employee;

print "1\n";
my $Me  = new Employee('Diederik van der Boor');
my $You = new Employee('Your Name Here');

print "2\n";
print 'me='.$Me->getName()."\n";

$Me->setName('YaPP');
print 'me='.$Me->getName()."\n";

print 'uu='.$You->getName() . "\n";

undef $Me;

print "3\n";
exit;
Small Details
This program (named Apl, like in Java) creates two Employee objects. The methods getName and setName are called during execution. The second object will be automatically destroyed when the program exits. Even then, the DESTROY subroutine will be called.
Program output
1
Constructor: Employee=HASH(0x182f064) Employee
Constructor: Employee=HASH(0x182f124) Employee
2
me=Diederik van der Boor
me=YaPP
uu=Your Name Here
Terminate:   Employee=HASH(0x182f064) Employee
3
Terminate:   Employee=HASH(0x182f124) Employee

Written by Diederik van der Boor at 30 January 2001