SlideShare una empresa de Scribd logo
1 de 37
Descargar para leer sin conexión
Practical Approach to PERL

      Rakesh Mukundan
Scripting Language

    Uses an interpreter to run the code

    No compilation needed, just run it!

    Interpreted line by line

    Fast to learn and program

    Easy debugging

    Every user is a developer :)
PERL
• Practical Extraction and Report Language
• Also known as Practically Everything
  Really Likeable
• Began as the result of one man's frustration
  and, by his own account, inordinate laziness 
• Perl is free. The full source code and
  documentation are free to copy, compile,
  print, and give away
Why Learn Perl
•   Perl is easy and it makes life easy!
•   Its open source
•   Lots of tested modules available for re-use
•   You are too lazy to do mechanical repetitive
    work 
Do You Have Perl Installed?

• Execute the following command in a shell
  –   perl -v
Installation
• UNIX and Linux : Available with installation CD or
  standard repositories if not installed by default

• Windows : Many flavors are available with and without
  IDEs, free and proprietary etc
   – Active State Perl
   – Strawberry Perl
Your First Perl Program
• Open MyFirstProgram.pl from the examples directory
  with your favorite text editor ( gedit,vim,notepad++
  etc )
• To run the program open up a shell and navigate to
  the examples directory
   • perl MyFirstProgram.pl
• In Linux systems perl file can be directly executed,
  provided path to interpreter has been specified
  correctly.
   • chmod a+x MyFirstProgram.pl
   • ./MyFirstProgram.pl
Under the hood


         Location of interpreter


                Comment




             A perl statement
             terminated with a
             semi-colon
Variables
• Place to store data
• A scalar variable stores a single value
• Perl scalar names are prefixed with a dollar
  sign ($)
   – Ex: $name,$password,$ip_address
• No need to define a variable explicitly, use
  directly
• A scalar can hold data of any type, be it a
  string, a number, or whatnot
Examples of Variables
•   $floating_val   =   3.14
•   $integer_val    =   1008
•   $string_val     =   “My String”
•   $hashReff       =   %HashToPoint;
•   $SubReff        =   MyRoutine();
•   $ScalarReff          = $floating_val;
Numerical Operations
Addition : $var1 + $var2
Subtraction : $var1 - $var2
Multiplication: $var1 * $var2
Division: $var1 / $var2
Increment: $var++
Power: $var1 ** $var2
Modulus: $var1 % $var2;
Contd..

    Greater than: $var1 > $var2

    Greater than or equal: $var1 >= $var2

    Less than : $var1 < $var2

    Less than or equal: $var1<= $var2

    Equality: $var1== $var2
Strings
An string of characters, no size limit
     “Hello World”
Can be specified using single quotes(') or
 double quotes(“)
Strings can be concatenated using dot (.)
 operator
No operations are possible inside a single
 quoted string
     “1 plus 2 is $value”
     '1 plus 2 is $value'
Strings
An string of characters, no size limit
     “Hello World”
Can be specified using single quotes(') or
 double quotes(“)
Strings can be concatenated using dot (.)
 operator
No operations are possible inside a single
 quoted string
     “1 plus 2 is $value”
     '1 plus 2 is $value'
Special Characters
L Transform all letters to lowercase
l Transform the next letter to lowercase
U Transform all letters to uppercase
u Transform the next letter to uppercase
n Begin on a new line
r Apply a carriage return
t Apply a tab to the string
EEnds U, L functions
Print Function
Most commonly used perl function
Can print a variable or string to
 console/file/any file handle
Usage print <file handle> expression
By default prints to STDOUT
     Print “Hello World n”;
     Print $MyVariable;
     Print “My name is $MyVariable n”;
     Print “One plus one is always 1+1 n”;
User Input

    <STDIN> stands for standard input

    Program waits for user to enter an input

    It will contain newline character also

    $MyAge= <STDIN>;

    chomp($MyAge);
Calculator Program
Ask user to enter two numbers
Do all the numerical operations mentioned in
 previous slide and print the output
String Operations
index(STR,SUBSTR) :Returns the position of
 the first occurrence of SUBSTR in STR
length(EXPR) :Returns the length in
 characters of the value of EXPR
rindex(STR,SUBSTR) :Works just like index
 except that it returns the position of the
 LAST occurrence of SUBSTR in STR
substr(EXPR,OFFSET,LEN):Extracts a sub
 string out of EXPR and returns it
Array
• List of scalars
• Similar to arrays in C,C++ etc..
• Array is identified by @ symbol
  • @FirstArray = (“one”,”two”,”three”);
• Each element can be accessed by its
  corresponding index
  • print $FirstArray[2];
Arrays
Visualizing Data In Perl

    Use the Dumper module
   use Data::Dumper;

    print Dumper $ref;

    $ref is the refference to the variable

    print Dumper @Array;

    print Dumper %Hash;
Working With Arrays
• An array element can be indexed as
  $MyFirstArray[1]
• push() - adds an element to the end of an
  array.
• unshift() - adds an element to the beginning
  of an array.
• pop() - removes the last element of an array.
• shift() - removes the first element of an
  array.
A phonebook
•   Pallava     => 3001
•   Krishna     => 3002
•   Godhavari   => 3003
•   Kaveri      => 3004

• How do you represent such a list?
  – Lookup by names?
Hashes
• Hash is a like a phone book which has names
  and corresponding phone numbers
• Each element in a hash will have a key and
  value
• For example
   – %PhoneBook = (
      • “pallava” => 3001,
      • “krishna” => 3002,
      • “godhavari”=> 3003,
      • “kaveri” => 3004);
Hashes
Working With Hash Values
• Each value can be accessed by its key
   – $Phonebook{“pallava”}
• To add a new value to hash table
   – $Phonebook{“nilgiris”} =”3005”;
• To delete a value from hash table
   – delete($Phonebook{“nilgiris”});
• Looping through a hashtable
   – while (($key, $value) = each(%Phonebook)){
   – Print $key.$value;
   –}
Contd..
• Checking if a particular key has already added in the
  hash table
   – if (exists($Phonebook{"pallava"}))
   –{
   –}
Program Control
•   If
•   While
•   For
•   Foreach
if
•
    Conditional statement to check if a criteria is
    met or not
•
    The syntax is
       •
           if(condtion){ code to execute;}
       •
           if($var1 ==5){
              •
                print “variable is 5n”;
       •
           }
ifelse

    Else is the compliment of if

    Execute code if the condition is not met

    Syntax
        
             if(condition){ code for condition met}
        
             else{ code for condition false}

    if($var1==5){
        
            print “variable value is 5n”;

    }

    else{
        
             Print “variable value is not 5n”;

    }
elsif
if(condition1){
     Code to execute
}
elsif(condition2){
    Code to execute
}
Else{
     Code to execute
}
while
•
    Loop while the condition is true
•
    while($count<5){
     •
         Print “Cont:$countn”;
     •
         $count++;
•
    }
•
    While(1) makes an infinite loop
•
    Flow Control
     •
         next :go to the next iteration
     •
         last:end while loop
for
•
    A for loop counts through a range of
    numbers, running a block of code
    each time it iterates through the loop
•
    for(initial, condition, $increment)
    { code to execute }
•
    for($count=0;$count<11;$count++)
    {
        •
            Print “Count $count n”;
•
    }
foreach
•
    Used for iterating over an array or hash
•
    foreach(@MyArray){
        •
            print “Element : $_n”;
•
    }
Phonebook Program

    Print existing numbers

    Option to add a new entry

    Option to delete and entry

    Option to exit the program

    Option to search by name
Strict Usage
By default perl doesn't need any variable to be
 declared before use
Simple spelling mistakes in variable names can
 lead to hours of code debugging!
By using the strict method,perl will strictly ask
 you declare variable
   my $MyFirstVar;
   my @MyFirstArray;
   my %MyFirstHash;

Más contenido relacionado

La actualidad más candente (20)

IO Streams, Files and Directories
IO Streams, Files and DirectoriesIO Streams, Files and Directories
IO Streams, Files and Directories
 
Perl bhargav
Perl bhargavPerl bhargav
Perl bhargav
 
Subroutines
SubroutinesSubroutines
Subroutines
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
 
Introduction in php part 2
Introduction in php part 2Introduction in php part 2
Introduction in php part 2
 
Php Intermediate
Php IntermediatePhp Intermediate
Php Intermediate
 
Working with text, Regular expressions
Working with text, Regular expressionsWorking with text, Regular expressions
Working with text, Regular expressions
 
1 4 sp
1 4 sp1 4 sp
1 4 sp
 
Programming in Computational Biology
Programming in Computational BiologyProgramming in Computational Biology
Programming in Computational Biology
 
Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)
 
Scalar data types
Scalar data typesScalar data types
Scalar data types
 
Perl
PerlPerl
Perl
 
Scripting3
Scripting3Scripting3
Scripting3
 
Perl programming language
Perl programming languagePerl programming language
Perl programming language
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
 
Perl 101 - The Basics of Perl Programming
Perl  101 - The Basics of Perl ProgrammingPerl  101 - The Basics of Perl Programming
Perl 101 - The Basics of Perl Programming
 
Php Chapter 2 3 Training
Php Chapter 2 3 TrainingPhp Chapter 2 3 Training
Php Chapter 2 3 Training
 
Lists and arrays
Lists and arraysLists and arrays
Lists and arrays
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Groovy unleashed
Groovy unleashed Groovy unleashed
Groovy unleashed
 

Similar a Practical approach to perl day1

Similar a Practical approach to perl day1 (20)

Learn perl in amc square learning
Learn perl in amc square learningLearn perl in amc square learning
Learn perl in amc square learning
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptx
 
Php basics
Php basicsPhp basics
Php basics
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
php fundamental
php fundamentalphp fundamental
php fundamental
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of php
 
php
phpphp
php
 
05php
05php05php
05php
 
MIND sweeping introduction to PHP
MIND sweeping introduction to PHPMIND sweeping introduction to PHP
MIND sweeping introduction to PHP
 
Intro to Perl and Bioperl
Intro to Perl and BioperlIntro to Perl and Bioperl
Intro to Perl and Bioperl
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Php basics
Php basicsPhp basics
Php basics
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
Introduction in php
Introduction in phpIntroduction in php
Introduction in php
 
Perl slid
Perl slidPerl slid
Perl slid
 
Bioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekingeBioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekinge
 
PHP-01-Overview.ppt
PHP-01-Overview.pptPHP-01-Overview.ppt
PHP-01-Overview.ppt
 

Último

Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...mriyagarg453
 
(Verified Models) Airport Kolkata Escorts Service (+916297143586) Escort agen...
(Verified Models) Airport Kolkata Escorts Service (+916297143586) Escort agen...(Verified Models) Airport Kolkata Escorts Service (+916297143586) Escort agen...
(Verified Models) Airport Kolkata Escorts Service (+916297143586) Escort agen...rahim quresi
 
Jodhpur Park ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi ...
Jodhpur Park ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi ...Jodhpur Park ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi ...
Jodhpur Park ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi ...ritikasharma
 
Hire 💕 8617697112 North Sikkim Call Girls Service Call Girls Agency
Hire 💕 8617697112 North Sikkim Call Girls Service Call Girls AgencyHire 💕 8617697112 North Sikkim Call Girls Service Call Girls Agency
Hire 💕 8617697112 North Sikkim Call Girls Service Call Girls AgencyNitya salvi
 
Kolkata Call Girls Service ❤️ at @30% discount Everyday
Kolkata Call Girls Service ❤️ at @30% discount EverydayKolkata Call Girls Service ❤️ at @30% discount Everyday
Kolkata Call Girls Service ❤️ at @30% discount Everydayonly4webmaster01
 
📞 Contact Number 8617697112 VIP East Sikkim Call Girls
📞 Contact Number 8617697112 VIP East Sikkim Call Girls📞 Contact Number 8617697112 VIP East Sikkim Call Girls
📞 Contact Number 8617697112 VIP East Sikkim Call GirlsNitya salvi
 
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034 Independent Chenna...
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034  Independent Chenna...Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034  Independent Chenna...
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034 Independent Chenna... Shivani Pandey
 
❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.Nitya salvi
 
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...rahim quresi
 
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...rahim quresi
 
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...rahim quresi
 
❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.Nitya salvi
 
𓀤Call On 6297143586 𓀤 Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...
𓀤Call On 6297143586 𓀤 Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...𓀤Call On 6297143586 𓀤 Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...
𓀤Call On 6297143586 𓀤 Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...rahim quresi
 
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...SUHANI PANDEY
 
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment BookingKanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment BookingNitya salvi
 
Thane West \ Escort Service in Mumbai - 450+ Call Girl Cash Payment 983332523...
Thane West \ Escort Service in Mumbai - 450+ Call Girl Cash Payment 983332523...Thane West \ Escort Service in Mumbai - 450+ Call Girl Cash Payment 983332523...
Thane West \ Escort Service in Mumbai - 450+ Call Girl Cash Payment 983332523...hotbabesbook
 
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034 Independent Chenna...
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034  Independent Chenna...Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034  Independent Chenna...
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034 Independent Chenna... Shivani Pandey
 
Low Rate Call Girls Dhakuria (8005736733) 100% GENUINE ESCORT SERVICE & HOTEL...
Low Rate Call Girls Dhakuria (8005736733) 100% GENUINE ESCORT SERVICE & HOTEL...Low Rate Call Girls Dhakuria (8005736733) 100% GENUINE ESCORT SERVICE & HOTEL...
Low Rate Call Girls Dhakuria (8005736733) 100% GENUINE ESCORT SERVICE & HOTEL... Shivani Pandey
 
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...rajveermohali2022
 
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser... Shivani Pandey
 

Último (20)

Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
 
(Verified Models) Airport Kolkata Escorts Service (+916297143586) Escort agen...
(Verified Models) Airport Kolkata Escorts Service (+916297143586) Escort agen...(Verified Models) Airport Kolkata Escorts Service (+916297143586) Escort agen...
(Verified Models) Airport Kolkata Escorts Service (+916297143586) Escort agen...
 
Jodhpur Park ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi ...
Jodhpur Park ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi ...Jodhpur Park ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi ...
Jodhpur Park ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi ...
 
Hire 💕 8617697112 North Sikkim Call Girls Service Call Girls Agency
Hire 💕 8617697112 North Sikkim Call Girls Service Call Girls AgencyHire 💕 8617697112 North Sikkim Call Girls Service Call Girls Agency
Hire 💕 8617697112 North Sikkim Call Girls Service Call Girls Agency
 
Kolkata Call Girls Service ❤️ at @30% discount Everyday
Kolkata Call Girls Service ❤️ at @30% discount EverydayKolkata Call Girls Service ❤️ at @30% discount Everyday
Kolkata Call Girls Service ❤️ at @30% discount Everyday
 
📞 Contact Number 8617697112 VIP East Sikkim Call Girls
📞 Contact Number 8617697112 VIP East Sikkim Call Girls📞 Contact Number 8617697112 VIP East Sikkim Call Girls
📞 Contact Number 8617697112 VIP East Sikkim Call Girls
 
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034 Independent Chenna...
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034  Independent Chenna...Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034  Independent Chenna...
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034 Independent Chenna...
 
❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Mukteshwar Call Girls 8617697112 💦✅.
 
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
 
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
 
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
 
❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.
 
𓀤Call On 6297143586 𓀤 Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...
𓀤Call On 6297143586 𓀤 Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...𓀤Call On 6297143586 𓀤 Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...
𓀤Call On 6297143586 𓀤 Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...
 
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
 
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment BookingKanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
 
Thane West \ Escort Service in Mumbai - 450+ Call Girl Cash Payment 983332523...
Thane West \ Escort Service in Mumbai - 450+ Call Girl Cash Payment 983332523...Thane West \ Escort Service in Mumbai - 450+ Call Girl Cash Payment 983332523...
Thane West \ Escort Service in Mumbai - 450+ Call Girl Cash Payment 983332523...
 
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034 Independent Chenna...
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034  Independent Chenna...Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034  Independent Chenna...
Verified Trusted Call Girls Tambaram Chennai ✔✔7427069034 Independent Chenna...
 
Low Rate Call Girls Dhakuria (8005736733) 100% GENUINE ESCORT SERVICE & HOTEL...
Low Rate Call Girls Dhakuria (8005736733) 100% GENUINE ESCORT SERVICE & HOTEL...Low Rate Call Girls Dhakuria (8005736733) 100% GENUINE ESCORT SERVICE & HOTEL...
Low Rate Call Girls Dhakuria (8005736733) 100% GENUINE ESCORT SERVICE & HOTEL...
 
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
 
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
 

Practical approach to perl day1

  • 1. Practical Approach to PERL Rakesh Mukundan
  • 2. Scripting Language  Uses an interpreter to run the code  No compilation needed, just run it!  Interpreted line by line  Fast to learn and program  Easy debugging  Every user is a developer :)
  • 3. PERL • Practical Extraction and Report Language • Also known as Practically Everything Really Likeable • Began as the result of one man's frustration and, by his own account, inordinate laziness  • Perl is free. The full source code and documentation are free to copy, compile, print, and give away
  • 4. Why Learn Perl • Perl is easy and it makes life easy! • Its open source • Lots of tested modules available for re-use • You are too lazy to do mechanical repetitive work 
  • 5. Do You Have Perl Installed? • Execute the following command in a shell – perl -v
  • 6. Installation • UNIX and Linux : Available with installation CD or standard repositories if not installed by default • Windows : Many flavors are available with and without IDEs, free and proprietary etc – Active State Perl – Strawberry Perl
  • 7. Your First Perl Program • Open MyFirstProgram.pl from the examples directory with your favorite text editor ( gedit,vim,notepad++ etc ) • To run the program open up a shell and navigate to the examples directory • perl MyFirstProgram.pl • In Linux systems perl file can be directly executed, provided path to interpreter has been specified correctly. • chmod a+x MyFirstProgram.pl • ./MyFirstProgram.pl
  • 8. Under the hood Location of interpreter Comment A perl statement terminated with a semi-colon
  • 9. Variables • Place to store data • A scalar variable stores a single value • Perl scalar names are prefixed with a dollar sign ($) – Ex: $name,$password,$ip_address • No need to define a variable explicitly, use directly • A scalar can hold data of any type, be it a string, a number, or whatnot
  • 10. Examples of Variables • $floating_val = 3.14 • $integer_val = 1008 • $string_val = “My String” • $hashReff = %HashToPoint; • $SubReff = MyRoutine(); • $ScalarReff = $floating_val;
  • 11. Numerical Operations Addition : $var1 + $var2 Subtraction : $var1 - $var2 Multiplication: $var1 * $var2 Division: $var1 / $var2 Increment: $var++ Power: $var1 ** $var2 Modulus: $var1 % $var2;
  • 12. Contd..  Greater than: $var1 > $var2  Greater than or equal: $var1 >= $var2  Less than : $var1 < $var2  Less than or equal: $var1<= $var2  Equality: $var1== $var2
  • 13. Strings An string of characters, no size limit  “Hello World” Can be specified using single quotes(') or double quotes(“) Strings can be concatenated using dot (.) operator No operations are possible inside a single quoted string  “1 plus 2 is $value”  '1 plus 2 is $value'
  • 14. Strings An string of characters, no size limit  “Hello World” Can be specified using single quotes(') or double quotes(“) Strings can be concatenated using dot (.) operator No operations are possible inside a single quoted string  “1 plus 2 is $value”  '1 plus 2 is $value'
  • 15. Special Characters L Transform all letters to lowercase l Transform the next letter to lowercase U Transform all letters to uppercase u Transform the next letter to uppercase n Begin on a new line r Apply a carriage return t Apply a tab to the string EEnds U, L functions
  • 16. Print Function Most commonly used perl function Can print a variable or string to console/file/any file handle Usage print <file handle> expression By default prints to STDOUT  Print “Hello World n”;  Print $MyVariable;  Print “My name is $MyVariable n”;  Print “One plus one is always 1+1 n”;
  • 17. User Input  <STDIN> stands for standard input  Program waits for user to enter an input  It will contain newline character also  $MyAge= <STDIN>;  chomp($MyAge);
  • 18. Calculator Program Ask user to enter two numbers Do all the numerical operations mentioned in previous slide and print the output
  • 19. String Operations index(STR,SUBSTR) :Returns the position of the first occurrence of SUBSTR in STR length(EXPR) :Returns the length in characters of the value of EXPR rindex(STR,SUBSTR) :Works just like index except that it returns the position of the LAST occurrence of SUBSTR in STR substr(EXPR,OFFSET,LEN):Extracts a sub string out of EXPR and returns it
  • 20. Array • List of scalars • Similar to arrays in C,C++ etc.. • Array is identified by @ symbol • @FirstArray = (“one”,”two”,”three”); • Each element can be accessed by its corresponding index • print $FirstArray[2];
  • 22. Visualizing Data In Perl  Use the Dumper module  use Data::Dumper;  print Dumper $ref;  $ref is the refference to the variable  print Dumper @Array;  print Dumper %Hash;
  • 23. Working With Arrays • An array element can be indexed as $MyFirstArray[1] • push() - adds an element to the end of an array. • unshift() - adds an element to the beginning of an array. • pop() - removes the last element of an array. • shift() - removes the first element of an array.
  • 24. A phonebook • Pallava => 3001 • Krishna => 3002 • Godhavari => 3003 • Kaveri => 3004 • How do you represent such a list? – Lookup by names?
  • 25. Hashes • Hash is a like a phone book which has names and corresponding phone numbers • Each element in a hash will have a key and value • For example – %PhoneBook = ( • “pallava” => 3001, • “krishna” => 3002, • “godhavari”=> 3003, • “kaveri” => 3004);
  • 27. Working With Hash Values • Each value can be accessed by its key – $Phonebook{“pallava”} • To add a new value to hash table – $Phonebook{“nilgiris”} =”3005”; • To delete a value from hash table – delete($Phonebook{“nilgiris”}); • Looping through a hashtable – while (($key, $value) = each(%Phonebook)){ – Print $key.$value; –}
  • 28. Contd.. • Checking if a particular key has already added in the hash table – if (exists($Phonebook{"pallava"})) –{ –}
  • 29. Program Control • If • While • For • Foreach
  • 30. if • Conditional statement to check if a criteria is met or not • The syntax is • if(condtion){ code to execute;} • if($var1 ==5){ • print “variable is 5n”; • }
  • 31. ifelse  Else is the compliment of if  Execute code if the condition is not met  Syntax  if(condition){ code for condition met}  else{ code for condition false}  if($var1==5){  print “variable value is 5n”;  }  else{  Print “variable value is not 5n”;  }
  • 32. elsif if(condition1){ Code to execute } elsif(condition2){ Code to execute } Else{ Code to execute }
  • 33. while • Loop while the condition is true • while($count<5){ • Print “Cont:$countn”; • $count++; • } • While(1) makes an infinite loop • Flow Control • next :go to the next iteration • last:end while loop
  • 34. for • A for loop counts through a range of numbers, running a block of code each time it iterates through the loop • for(initial, condition, $increment) { code to execute } • for($count=0;$count<11;$count++) { • Print “Count $count n”; • }
  • 35. foreach • Used for iterating over an array or hash • foreach(@MyArray){ • print “Element : $_n”; • }
  • 36. Phonebook Program  Print existing numbers  Option to add a new entry  Option to delete and entry  Option to exit the program  Option to search by name
  • 37. Strict Usage By default perl doesn't need any variable to be declared before use Simple spelling mistakes in variable names can lead to hours of code debugging! By using the strict method,perl will strictly ask you declare variable  my $MyFirstVar;  my @MyFirstArray;  my %MyFirstHash;