Skip to content

Impatient Perl

December 12, 2013

Perl is a Top 20 language on the TIOBE index and gets a lot of attention on Github as well. So after Googling for free e-books on Perl, I found that there are many available for free. So I chose the book with the biggest value for my time “Impatient Perl”.

Impatient Perl is only 136 pages long with 22 chapters. Some of the chapters were exceptionally short, and some were even mere dividers between sections of the book. Below I’ll provide a breakdown of the important chapters and a list of tips that I found useful and/or interesting.

While Chapter 1 goes over some history and some vocabulary that would be encountered throughout the book, the real meat start off with the lengthy Chapter 2. Chapter 2 covers the basic syntax of the language plus an overview of some common subroutines you’re likely to encounter.

The extremely small and self explanatory chapters were: Ch3-Control Flow- next/last/redo, Ch6-Compiling & Interpreting- BEGIN, CHECK, INIT, END blocks and order usage, Ch7-Perl Modules- are .pm files that must have “1” as their last line, Ch8-use statements, Ch12-procedural programming definition, and Ch16-the next level-divider between sections.

Below are some tips I wrote down from the various other chapters:

  • Packages/Namespaces/Scoping
    • package variables are permanent and never go out of scope or get GC-ed.
    • local(package_variable) – take a snapshot of the global variable’s state.
  • Subroutines
    • Symbols $,%,@,& (scalar, hash, array, subroutine) are called sigils.
    • Subroutine arguments (@_) are list contexts with no knowledge of original containers.
    • Subroutine parameters are effectively IN/OUT. Changes within subroutine affect data outside of subroutine.
  • Use statement formally
    • @INC defines module search directories
    • use lib ‘/somepath’; is the preferred way to manipulate @INC
    • use lib glob(“~/code”); to get unix ~ to evaluate correctly
    • require causes module->import(listArgs);
  • Bless – all it does is affect the value returned by ref();
  • Method calls
    • Has 2 features: invocant is found first in @_ and uses inheritance.
    • @ISA defines inheritance hierarchy for a particular object/class.
    • caller->isa(“base package”); # return true/false
    • caller->can(“method name”); # if the caller can respond to that method name.
  • Object Oriented Perl
    • Constructors usually ClassName->new(args), but method can be named anything.
    • Before GC “sub destroy” is called to cleanup each object.
    • To call base class overriden method use $caller->SUPER::method
  • CPAN – comprehensive perl archive network
    • POD – plain old documentation format.
    • h2xs – utility to create/upload perl modules to CPAN.
    • perl Makefile.PL – is similar to autoconf in that it generates a ready to use Makefile
  • Command line arguments
    • @ARGV – contains command line parameters in a special array.
    • For complicated option parsing use Getopt::Declare
  • File I/O – perldoc File::Find
  • Operating system commands – system() to get error codes only OR backticks (`) for STDOUT in a return string
  • Regular Expressions – good amount of detail, but not covered since it matches my understanding of RegEx in Ruby.
  • Parse::RecDescent – topdown recursive descent trying a list of rules which is a good, but slower approach when regular expressions are insufficient.
  • Perl, GUI, Tk – Short chapter on the Perl/Tk interaction

From → Books

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: