Difference between revisions of "PERL"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Basic Level)
Line 39: Line 39:
 
#** =cut =head or =begin =end
 
#** =cut =head or =begin =end
 
#**Start with = sign
 
#**Start with = sign
#Loops in Perl
+
#:<br>
 +
#: '''Loops in Perl'''
 +
# for-foreach-Loop
 
#* for Loop
 
#* for Loop
 
#** for loop is used to execute a piece of code for certain number of times
 
#** for loop is used to execute a piece of code for certain number of times
Line 49: Line 51:
 
array</nowiki><br><nowiki>}</nowiki>
 
array</nowiki><br><nowiki>}</nowiki>
 
#** eg:<br><nowiki>@myarray = (10, 20, 30);</nowiki><br><nowiki>foreach $var (@myarray)</nowiki><br><nowiki>{</nowiki><br><nowiki>print “Element of array is: $var \n”;</nowiki><br><nowiki>}</nowiki>
 
#** eg:<br><nowiki>@myarray = (10, 20, 30);</nowiki><br><nowiki>foreach $var (@myarray)</nowiki><br><nowiki>{</nowiki><br><nowiki>print “Element of array is: $var \n”;</nowiki><br><nowiki>}</nowiki>
 +
# while-do-while Loops
 
#* while Loop
 
#* while Loop
 
#** while loop executes a block of code while a condition is true.
 
#** while loop executes a block of code while a condition is true.

Revision as of 14:11, 29 January 2013

Introduction to Perl

Perl (Practical Extraction & Reporting Language) is widely used open-source language. It was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular amongst programmers. Larry Wall continues to work on development of the core language, and its upcoming version, Perl 6. Perl borrows features from other programming languages including C, shell scripting (sh), AWK, and sed. The language provides powerful text processing facilities, facilitating easy manipulation of text files. Perl gained widespread popularity in the late 1990s as a CGI scripting language, in part due to its parsing abilities.

Perl can be used as a very simple and easy to use programming language. This language helps programmer to write a simple piece of code against the heavy / complicated shell or C programming. This language is portable and reliable. Useful for applications requiring Pattern Matching extensively

Basic Level

Installation of Perl
  1. Installation of Perl 5.14.2 on Ubuntu Linux
    • Installing XAMPP in Linux
    (XAMPP is a cumulative package consisting of Apache, PERL, PHP and MySQL Packages is available for Linux)
    • Default Webserver directory will be set to "opt"
    OR
    • Using default Perl installation available in Synaptic Package Manager
  2. Installation of Perl 5.14.2 on Windows
    • Installing XAMPP in Windows
    (XAMPP is a cumulative package consisting of Apache, PERL, PHP and MySQL Packages is available for Windows)
    • Default Webserver directory will be set to "htdocs"

    Topics
  3. Variables in Perl
    • Variables are used for storing values, like text strings, numbers or arrays
    • All variables in PERL start with a $ sign symbol
    • Declaring a variable in PERL: $var_name = value;
    • e.g:
      • $count = 1;
      • $stringVar = ‘My Name is PERL’;
  4. Comments in Perl
    • Two types of comments -
      • Single Line
      • Multi Line
    • Single Line comment starts with the symbol #
    • Multi Line comment used to comment a chunk of code
      • =cut =head or =begin =end
      • Start with = sign

    Loops in Perl
  5. for-foreach-Loop
    • for Loop
      • for loop is used to execute a piece of code for certain number of times
      • Syntax:
        for (initialization;condition;increment)
        {
        Piece of code to be executed multiple times
        }
      • eg:
        for ($i=0; $i<=4; $i++)
        {
        print “Value of i: $i\n”;
        }
    • for-each Loop
      • for-each loop is used to iterate a condition over an array
      • Syntax:
        foreach $variable (@array)
        {
        Perform action on each element of array
        }
      • eg:
        @myarray = (10, 20, 30);
        foreach $var (@myarray)
        {
        print “Element of array is: $var \n”;
        }
  6. while-do-while Loops
    • while Loop
      • while loop executes a block of code while a condition is true.
      • Syntax:
        while (condition)
        {
        Piece of code to be executed only while the condition is true
        }
      • eg:
        $i = 0;
        while ($i<=4)
        {
        print “Value of i: $i\n”;
        $i++;
        }
    • do-while Loop
      • do-while loop will always execute the piece of code at-least once
      • It will then check the condition and repeat the loop while the condition is true
      • Syntax:
        do
        {
        Piece of code to be executed while the condition is true
        }do (while);
      • eg:
        $i = 0;
        do
        {
        print “Value of i: $i\n”;
        $i++;
        }while ($i<=4);
  7. Conditional Statements
    • if Statement
    • if-else Statement
    • if-elsif-else Statement
    • switch Statement
  8. Data Structures in Perl
    • Scalar
    • Array
    • Associative Array or Hash
  9. More on Arrays
    • Getting length of an array
    • Accessing element of an array
    • Looping over an array
    • Basic array functions
      • push
      • pop
      • unshift
      • shift
      • split
      • qw
      • sort
  10. More on Hash
    • Accessing element of a hash
    • Basic hash functions
      • keys
      • values
      • each
    • Looping over a hash
  11. Functions in Perl
    • Simple function
    • Function with parameters
    • Function which return single value
    • Function which returns multiple values
  12. Blocks in Perl
    • Begin
    • End

Intermediate level

Topics
  1. Access Modifiers in PERL
    • my
    • local
    • our
  2. Referencing & Dereferencing in Perl
    • Referencing
    • De-referencing
  3. Special Variables in PERL
  4. Sample Perl Programs
  5. Exception and error handling in PERL
    • eval block in perl
  6. File Handling
    • open a file
    • open a file in read mode
    • open a file in read, write mode
    • open a file in append mode
    • write into a file
    • close the file handle
  7. Including files and/or modules in a PERL program
    • do
    • require
    • use
  8. Perl Modules
  9. PERL Module library
    • CPAN
  10. Adding path to a default list of paths for a module
    • @INC
  11. Downloading required module onto windows or linux
    • Downloading CPAN module
      • WindowsLinux
  12. PERL & HTML
    • CGI module

Advanced level

Topics
  1. Function Prototyping
  2. Date & Time
    • Current Time Stamp
    • Various Date formats
    • Various operations that can be performed on date
  3. Oops in Perl
    • Object creation
    • Constructor
    • Destructor
    • Accessing methods using an object
    • Inheritance in Per
  4. Exporting functions in Perl
    • EXPORT
    • EXPORT_OK
  5. Pattern Matching / Regular expression in Perl
    • Basics of pattern matching
    • Syntax
    • Modifiers
  6. Database handling
    • DBI module
  7. Multithreading
    • threads module
  8. Socket Programming
    • use IO::Socket::INET
  9. General information
    • Getting Perl version
    • Perl installation path
    • Information about the
      • module
      • it’s location
      • from where it is included in your perl script

Contributors and Content Editors

AmolBrahmankar, Nancyvarkey, Nirmala Venkat, PoojaMoolya