Perl Language Overview

Introduction

  • Using Perl version 5.10 (five.ten)
  • Perl = Practical Extraction and Report Language (only one of many names people use to call it)
    • Larry Wall – creator
    • 1980s – heavily uses Unix commands
    • Use shell or awk programming with advanced tools like grep, cut, sort and sed but without having the complexities of a language like C
  • Perl is easy to use but hard to learn
  • Perl is high level language
    • Like C or Java – human readible
  • Perl is faster to write, read, debug and maintain than most other high-level languages
    • Because it is scripting language, doesn’t come with all the language formalities like Java
  • Perl is excellent for quick programs, to solve quick and specific problems
  • Perl has no opaque binary source, no compile file. Perl programs are exchanged through source code. Therefore perl programs are difficult to keep closed-source.
  • Perl is about 90% dealing with text, 10% everything else.
    • Perl is excellent at parsing or working with Text
  • CPAN – Comprehensive Perl Archive Network
    • Search.cpan.org
    • Kobesearch.cpan.org
  • Other Perl sites
    • www.pm.org
    • www.perlmonks.org
    • Learn.perl.org
    • Planet.perl.org

Perl Programming

  • Hello World Program:
#!/usr/bin/perl 
 print "Hello World!\n";
 #Or in Perl 5.10 -> say "Hello World!";
  • In Unix – the “#!” indicates to the OS to run the remainder of file using that program
  • Perl Compiler – the perl interpreter compiles and runs the program in one user step
  • The internal compiler first runs through entire source, then turns it into bytecode
    • Syntax errors are displayed with line numbers
    • Usually compiler is fast and should not affect runtime
    • For some websites where multiple users might call the same perl program several times, one could use CGI::Fast
  • Exercises:
    • Perldoc -u -f atan2
=item atan2 Y,X
 Returns the arctangent of Y/X in the range -PI to PI.
 For the tangent operation, you may use the C<POSIX::tan()>
 function, or use the familiar relation:
 sub tan { sin($_[0]) / cos($_[0]) }