Perl
http://www.perl.org
Installation
- installers for windows, linux and solaris
- source for virtually any platform
Tutorials
Project Setup
# create a folder "Talker"
# create a file "talker.pm"
# create a file "main.pl"
# from command line
# $ perl main.pl
# interactive shell
# cmd> perl -de0
# DB<1> use Talker;
# DB<2> $john = Talker->new;
# DB<3> $john->sayHello;
# within file "Talker.pm"
package Talker;
sub new {
my $class = shift;
bless {} => $class;
}
sub sayHello {
print "Hello world";
}
1;
# add to Talker.pm
# uses a CPAN module for convenience
use base qw/Class::Accessor/;
__PACKAGE__->mk_accessors(qw/name age/);
sub sayYourName {
print shift->name;
}
sub sayYourAge {
print shift->age;
}
sub sayYourClassName {
print ref shift;
}
sub sayYourInstanceVarName {
print "LIMITATION: InstanceVarName not available";
}
sub thisMethodName {
((caller(1))[3] || "") =~ /.*::(.*)/ ? $1 : "(anonymous)";
}
sub sayHelloAdvanced {
print shift->thisMethodName, ": Hello world";
}
sub sayYourClassDefinition {
print "LIMITATION: Reflection not available";
}
# note: does _not_ use reflection, but is file based
# This requires the token __DATA__ be the last thing in Talker.pm
sub sayYourClassCode {
seek DATA, 0, 0; # :-)
local $/;
print <DATA>;
}
# within main.pl
use Talker;
my $john = Talker->new;
$john->sayHello;
$john->name("John Doe Perl");
$john->age(19);
$john->sayYourName;
$john->sayYourAge;
$john->sayYourClassName
$john->sayYourInstanceVarName
$john->sayHelloAdvanced
$john->sayYourClassDefinition
$john->sayYourClassCode