1/24/2015

Advanced Perl Notes

Advanced Perl Notes

Like many of my blog entries, Advanced Perl Notes is my own list of notes on a subject.  It is one of the worst organized.

Using &subname defaults to call a subroutine in the current package.

Class methods are package methods in the form: PackageName->MethodName();

The my variables are not scoped to a particular package

$VERSION must be placed in a package that has the same name as the file (without the .pm)

File names conventionally match package names

Loading a Perl module like Module.pm with use Module happens at compile time, but loading a module with require Module happens at runtime.

Perl libraries like syslog.pl can be loaded with do syslog.pl  or require syslog.pl.  Require does error checking, and is preferred.  Libraries have difficulty using other libraries so modules are preferred.

Along with references and modules,  Perl release 5.000,  added objects.  

When you use the ref function on an object, it will return the name of the class it belongs to.

sub class_only_method {
    my $class = shift;
    die "class method called on object" if ref $class;
    # more code here
} 

If you want to allow a particular method to be called as an instance method only, do something like this:
sub instance_only_method {
    my $self = shift;
    die "instance method called on class" unless ref $self;
    # more code here
} 

To format dates and times:
use POSIX 'strftime';
print strftime 'Today is %x', localtime



No comments:

About Me - WrightRocket

My photo

I've worked with computers for over 30 years, programming, administering, using and building them from scratch.

I'm an instructor for technical computer courses, an editor and developer of training manuals, and an Android developer.