Welcome to my site. I use this site as a repository to dump knowledge I come across, generally in the areas of software engineering and information technologies, but may include other miscellaneous tidbits. Most of the posts are written as notes for my personal reference.
if i.hear then
i.forget
if i.see then
i.remember
if i.do then
i.understand
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 […]
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 […]
Matching with Regular Expressions (Regex) Modifiers /i # case insensitive /s # match any character, regardless of newlines /x # ignore whitespace. Example, to match floating point numbers: -? # optional minus sign \d+ # one or more digits \.? # optional decimal point \d* # zero or more optional digits after decimal point /x […]
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 […]
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 […]
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 […]
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 […]
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 […]
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; […]
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 […]