Managing Processes in Perl

The system Function Calls other programs Creates a child process to run the program being called Perl inherits the standard input, output and error Therefore if the program is printing something, that will automatically go through Perl’s STDOUT Perl waits for the child process to finish Like done on the shell, Perl can also launch […]

Perl Modules

The properties of Perl Modules: Modules either come with Perl or can be downloaded from CSPAN Modules can also be custom written Libraries also exist, but the difference is: Libraries mostly contain similar subroutines Modules is like a “smart library” – offers collection of subroutines that act as if they were build in functions Modules […]

Control Structures in Perl

The “unless” control structure Opposite of the “if” condition Only executes the code block if the condition is FALSE # UNLESS Control Structure $_ = “foey foo foobar!”; unless (/foobarz/) { print “Inside of UNLESS block \n”; } # this prints unless (/foobar/) { print “Inside of UNLESS block \n”; } # this does NOT […]

Regular Expressions

Regular expressions, often called pattern in Perl, is a template that either matches or doesn’t match a given string. Metacharacters o When referencing groups, remember that perl takes the last group value . # match any single character except newline \ # use literal value of next character * # quantifier, match zero or more […]

Hashes in Perl

Hash is an associative array o A data structure with key – value, where the key is a unique string o Perl processes big hashes just as fast as small ones. Hashes are most useful when dealing with Finding duplicates Unique Cross reference Lookup table Hash expression: $hash{$key} = $value; $hash{$key} .= $hash{$key2}; #creates key […]

Working with Input and Outputs in Perl

Input from Standard Input o Common way to input from standard input: chomp($line = <STDIN>); Reading continuous input would look something like: while ( chomp($line = <STDIN>) ) {…} # or while (defined($_ = <STDIN>)) { … } The Diamond Operator < > o Useful for making programs that work like standard Unix utilities, with […]

Subroutines in Perl

Defining Subroutines o Use the keyword sub o Subroutines can have ampersand (&) in the front of the name or not o By default, all subroutines are global (public); requires advanced methods to make them private o Two of the exact same subroutine names can be defined, but the first one is overrided by the […]

Lists and Arrays in Perl

Scalar represents “singular” in Perl. The “plural” are represented through Lists and Arrays List is an ordered collection of scalars Array is a variable that contains a list Element of an array or list is a separate scalar variable List is the data, array is the variable representing the list. There are no size limits […]

Perl Data Types (Scalar) and Common Operators

Scalar Data A scalar is the simplest kind of data that Perl manipulates String of characters primatives Numbers Perl always uses double-point precision for values (no difference between floats or integers) Examples: #Numbers $myint1 = 123456; $myint2 = 123_456; # can use _ anywhere in number $mybig1 = 1.23e10; # e notation $mysmall1 = 0xff; […]

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 […]