SlideShare a Scribd company logo
Perl Scripting




        M. Varadharajan
Thiagarajar College of Engineering
What We Will Cover?
   What is Perl?
   Creating and Executing Perl scripts
   Standard Input and Output
   Scalar Variables
   Arrays
   Hashes
   Magic Variables: $_ and @ARGV
What We Will Cover?
   Control Structures
   Looping Structures
   File Operations
   Split & Join
   Using shell commands
   Advanced Concepts you'll need to know
What is Perl
   Perl stands for
        −   'Practical Extraction and Reporting Language'
   Developed by Larry Wall in 1987
   Its called Perl and not PERL
   High level Scripting Language
   Dynamically Typed
   Support for object oriented programming
Some Advantages of Perl
   Free and Open source
   Fast, Flexible, Secure and Fun
   Interpreted Language
   Mature Community
   Portability
   Very good Documentation (POD)
   Availability of Modules (CPAN)
Typical Uses of Perl
   Text processing
   System administration tasks
   CGI and web programming
   Database interaction
   Other Internet programming
Hello World!
   This script will print 'Hello World!'
   Creation of the Perl Script:
        −   Open your Text Editor (!MSWORD)
        −   Type the following block & save

               #!/usr/bin/perl -w
               print “Hello World! n”;
Hello World!
   Some point to Note:
       −   All Perl statements end with ';'
       −   Add 'use strict;' if you're serious on the
           script
       −   Comments in Perl start with '#'
       −   The first line is known as Shebang line
                  #!/usr/bin/perl -w
Hello World!
   Executing the script:
        −   Call the interpreter with the script
                     perl helloworld.pl


                     or

        −   Grant Executable Permissions & Execute
                    Chmod a+x helloworld.pl
                    ./helloworld.pl
Scalar Variables
   Place to store a single item of data
   Scalar variables begin with '$'
   Declaration is as follows (in strict mode)
               my $name;
   Assigning values is similar to c
               $name = “varadharajan”;
               $total = 100;
               $cost = 34.34
Standard Output
   Print function is used
   Syntax:
              print “some string”;


   Example: (script prints “Perl is cool”)
              #/usr/bin/perl -w
              my $name = “perl”;
              print “$name is cool n”;
Standard Input
   Special operator '<>' is used
   Synatx:
              $scalar = <STDIN>;
   Example: (Get name and print it)
              #/usr/bin/perl -w
              print “Enter Name : ”;
              my $name = <STDIN>;
              print “Hello $name”;
String Operations
   Chomp:
              chomp($name);
              #removes the trailing new line
   Concatenation:
              my $name = “Varadharajan ” . “Mukundan”;
   Multiplication:
              $name = “hello ” x 3;
              #Assigns “hello hello hello” to name
Arrays
   Set of Scalar variables
   Arrays start with '@'
   Declaring Arrays:
        −   Syntax:
              my @array_name=(value1,value2);
        −   Example:
              my @list = ('varadharajan',99,'cool');
Arrays
   Accessing individual elements:
       −   Syntax:
             $array_name[index];
             #index starts with 0


       −   Example:
             print $list[1]; #prints 10
Array Slices
   Access a set of continuous elements in an
    array.
       −   Syntax:
             @array_name[start_index .. end_index];
       −   Example:
             print @list[ 0 .. 2 ];
             # Prints $list[0], $list[1], $list[2]
Hashes
   “Key – value ” Data Structure.
   Keys present in a hash must be unique
   Value may be same for multiple keys
   Also commonly known as dictionaries
Hashes
   Initializing a Hash:
        −   Syntax:
              my %hash_name = ( key => 'value');
        −   Example:
              my %students = (
                               name => 'varadharajan',
                                age => 1
                             );
Hashes
   Accessing a Hash
       −   Syntax:
             $hash_name{key_name};
       −   Example:
             print $student{name};
             #prints varadharajan
             print $student{age};
             #prints 18
Hash Slices
   Just like array slices
   Syntax:
               @hash_name{'key1','key2'};
   Example:
               print @student{'name','age'};
Magic Variable: $_
   Default variable for storing values, if no
    variables are manually specified.
   Example:
              my @list = (1,2,4,34,5,223);
              foreach (@list)
              {
                    print;
              }
              # prints the entire list
Magic Variable: @ARGV
   This Array is used to store the command
    line arguments
   Example
             print $ARGV[0];
             # when this script is executed like this
             # perl test1.pl text
             # it prints “text”
Conditional control Structures
   IF – ELSIF – ELSE statement:
       −   Syntax:
             if (EXPR) {BLOCK}
             elsif (EXPR) {BLOCK}
             else {BLOCK}
       −   Example:
             if($age==18) {print “Eighteen”;}
             elsif($age==19) {print “Nineteen”}
             else {print $age;}
Looping Structures
   While:
             $i = 0;
             while ($i < 10)
             {
                   print $i;
                   $i++;
             }
             # Prints 0123456789
Looping Structures
   For:
           for($i=0;$i<10;$i++)
           {
                 print $i;
           }
           # prints 0123456789
Looping Structures
   Foreach:
               my @list = (“varadha”,19);
               foreach $value (@list)
               {
                     print $value;
               }
               # prints the list
File Operations
   Opening a File:
       −   Syntax:
             open(FILE_HANDLE , “[< |> |>>]File_Name”);
       −   Example:
             open(MYFILE, “<myfile.txt”);
       −   Available Modes:
             < - Read Mode
             > - Write Mode
             >> - Append Mode
File Operations
   Reading from a File:
       −   Syntax:
             @array_name = <FILE_HANDLE>;
       −   Example:
             @data = <MYFILE>;
             # Now @data contains the data presents in
             # File whose file handle is MYFILE
File Operations
   Writing to a File:
        −   Syntax:
              print FILE_HANDLE “Text”;
        −   Example:
              print MYFILE “This is the content”;
File Operations
   Closing a File:
        −   Syntax:
              close(FILE_HANDLE);
        −   Example:
              close(MYFILE);
Split Function
   Splits a scalar variable into arrays
        −   Syntax:
              @array = split(PATTERN,EXPR);
        −   Example:
              @words = split(/ /,$sentence);
Join Function
   Used to join all elements in an array to
    form a scalar
        −   Syntax:
              $string = join(Joining_element,@arrays);
        −   Example:
              $sentence = join(' ',@words);
Executing Shell Commands
   Makes us executed Shell commands from
    a Perl script
       −   Syntax:
             system(command);
       −   Example:
             $ls_data = system(“ls”);
Advanced Concepts
   Subroutines
   Global and Local variables
   Regular Expressions
   OO programming
   CPAN
Perl Resources
   Perl POD
   Learning Perl from o'reilly
   Programming Perl from o'reilly
   Perl Beginners Mailing list at
     http://www.nntp.perl.org/group/perl.beginn
       ers/
That's All Folks
   Ping me at srinathsmn@gmail.com



                 Thank You

More Related Content

What's hot

Java program structure
Java program structure Java program structure
Java program structure
Mukund Kumar Bharti
 
Strings in python
Strings in pythonStrings in python
Strings in python
Prabhakaran V M
 
File Management in C
File Management in CFile Management in C
File Management in C
Paurav Shah
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
Sathish Narayanan
 
file handling c++
file handling c++file handling c++
file handling c++Guddu Spy
 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5
Vikram Nandini
 
Perl Programming - 01 Basic Perl
Perl Programming - 01 Basic PerlPerl Programming - 01 Basic Perl
Perl Programming - 01 Basic Perl
Danairat Thanabodithammachari
 
Strings in c
Strings in cStrings in c
Strings in c
vampugani
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Pavith Gunasekara
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa
 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
Maruf Abdullah (Rion)
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
Vibrant Technologies & Computers
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design
Aman Sharma
 
Array,lists and hashes in perl
Array,lists and hashes in perlArray,lists and hashes in perl
Array,lists and hashes in perl
sana mateen
 
String in c
String in cString in c
String in c
Suneel Dogra
 
ITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in java
Atul Sehdev
 
Variables in python
Variables in pythonVariables in python
Variables in python
Jaya Kumari
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Kengatharaiyer Sarveswaran
 

What's hot (20)

Java program structure
Java program structure Java program structure
Java program structure
 
Strings in python
Strings in pythonStrings in python
Strings in python
 
File Management in C
File Management in CFile Management in C
File Management in C
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
file handling c++
file handling c++file handling c++
file handling c++
 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5
 
Perl Programming - 01 Basic Perl
Perl Programming - 01 Basic PerlPerl Programming - 01 Basic Perl
Perl Programming - 01 Basic Perl
 
Strings in c
Strings in cStrings in c
Strings in c
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
Strings in C
Strings in CStrings in C
Strings in C
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design
 
Lesson 5 php operators
Lesson 5   php operatorsLesson 5   php operators
Lesson 5 php operators
 
Array,lists and hashes in perl
Array,lists and hashes in perlArray,lists and hashes in perl
Array,lists and hashes in perl
 
String in c
String in cString in c
String in c
 
ITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in java
 
Variables in python
Variables in pythonVariables in python
Variables in python
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 

Viewers also liked

LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
Dave Cross
 
Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2Dave Cross
 
Perl hosting for beginners - Cluj.pm March 2013
Perl hosting for beginners - Cluj.pm March 2013Perl hosting for beginners - Cluj.pm March 2013
Perl hosting for beginners - Cluj.pm March 2013Arpad Szasz
 
Introduction to Web Programming with Perl
Introduction to Web Programming with PerlIntroduction to Web Programming with Perl
Introduction to Web Programming with PerlDave Cross
 
Database Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::ClassDatabase Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::ClassDave Cross
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languagesVarun Garg
 
Linux.ppt
Linux.ppt Linux.ppt
Linux.ppt
onu9
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
Nowell Strite
 
Perl University: Getting Started with Perl
Perl University: Getting Started with PerlPerl University: Getting Started with Perl
Perl University: Getting Started with Perl
brian d foy
 
Perl Introduction (OLD - NEARLY OBSOLETE)
Perl Introduction (OLD - NEARLY OBSOLETE)Perl Introduction (OLD - NEARLY OBSOLETE)
Perl Introduction (OLD - NEARLY OBSOLETE)
Adam Trickett
 
Ascii codes 3145_app_f
Ascii codes 3145_app_fAscii codes 3145_app_f
Ascii codes 3145_app_f
Sivajyothi Chandra
 
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 ProgrammingUtkarsh Sengar
 
DBI
DBIDBI
Web Development in Perl
Web Development in PerlWeb Development in Perl
Web Development in Perl
Naveen Gupta
 
Mojolicious. The web in a box!
Mojolicious. The web in a box!Mojolicious. The web in a box!
Mojolicious. The web in a box!
Anatoly Sharifulin
 
Web Operations and Perl kansai.pm#14
Web Operations and Perl kansai.pm#14Web Operations and Perl kansai.pm#14
Web Operations and Perl kansai.pm#14Masahiro Nagano
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
Dave Cross
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
Dave Cross
 
Sql ppt
Sql pptSql ppt
Sql ppt
Roni Roy
 

Viewers also liked (20)

LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
 
Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2
 
Perl hosting for beginners - Cluj.pm March 2013
Perl hosting for beginners - Cluj.pm March 2013Perl hosting for beginners - Cluj.pm March 2013
Perl hosting for beginners - Cluj.pm March 2013
 
Introduction to Web Programming with Perl
Introduction to Web Programming with PerlIntroduction to Web Programming with Perl
Introduction to Web Programming with Perl
 
Database Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::ClassDatabase Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::Class
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
 
Linux.ppt
Linux.ppt Linux.ppt
Linux.ppt
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Perl University: Getting Started with Perl
Perl University: Getting Started with PerlPerl University: Getting Started with Perl
Perl University: Getting Started with Perl
 
Questionnaire Analysis
Questionnaire AnalysisQuestionnaire Analysis
Questionnaire Analysis
 
Perl Introduction (OLD - NEARLY OBSOLETE)
Perl Introduction (OLD - NEARLY OBSOLETE)Perl Introduction (OLD - NEARLY OBSOLETE)
Perl Introduction (OLD - NEARLY OBSOLETE)
 
Ascii codes 3145_app_f
Ascii codes 3145_app_fAscii codes 3145_app_f
Ascii codes 3145_app_f
 
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
 
DBI
DBIDBI
DBI
 
Web Development in Perl
Web Development in PerlWeb Development in Perl
Web Development in Perl
 
Mojolicious. The web in a box!
Mojolicious. The web in a box!Mojolicious. The web in a box!
Mojolicious. The web in a box!
 
Web Operations and Perl kansai.pm#14
Web Operations and Perl kansai.pm#14Web Operations and Perl kansai.pm#14
Web Operations and Perl kansai.pm#14
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Sql ppt
Sql pptSql ppt
Sql ppt
 

Similar to Perl Scripting

Perl Basics for Pentesters Part 1
Perl Basics for Pentesters Part 1Perl Basics for Pentesters Part 1
Perl Basics for Pentesters Part 1
n|u - The Open Security Community
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
worr1244
 
Lecture 22
Lecture 22Lecture 22
Lecture 22rhshriva
 
Introduction to perl_lists
Introduction to perl_listsIntroduction to perl_lists
Introduction to perl_lists
Vamshi Santhapuri
 
Training on php by cyber security infotech (csi)
Training on  php by cyber security infotech (csi)Training on  php by cyber security infotech (csi)
Training on php by cyber security infotech (csi)
Cyber Security Infotech Pvt. Ltd.
 
Subroutines
SubroutinesSubroutines
Perl
PerlPerl
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Practical approach to perl day1
Practical approach to perl day1Practical approach to perl day1
Practical approach to perl day1
Rakesh Mukundan
 
Marc’s (bio)perl course
Marc’s (bio)perl courseMarc’s (bio)perl course
Marc’s (bio)perl course
Marc Logghe
 
Perl bhargav
Perl bhargavPerl bhargav
Perl bhargav
Bhargav Reddy
 
Intro to PHP
Intro to PHPIntro to PHP
Intro to PHP
Sandy Smith
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Andrea Telatin
 

Similar to Perl Scripting (20)

Perl Basics for Pentesters Part 1
Perl Basics for Pentesters Part 1Perl Basics for Pentesters Part 1
Perl Basics for Pentesters Part 1
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
Introduction to perl_lists
Introduction to perl_listsIntroduction to perl_lists
Introduction to perl_lists
 
Training on php by cyber security infotech (csi)
Training on  php by cyber security infotech (csi)Training on  php by cyber security infotech (csi)
Training on php by cyber security infotech (csi)
 
Subroutines
SubroutinesSubroutines
Subroutines
 
Perl
PerlPerl
Perl
 
Dades i operadors
Dades i operadorsDades i operadors
Dades i operadors
 
My shell
My shellMy shell
My shell
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
SHELL PROGRAMMING
SHELL PROGRAMMINGSHELL PROGRAMMING
SHELL PROGRAMMING
 
Practical approach to perl day1
Practical approach to perl day1Practical approach to perl day1
Practical approach to perl day1
 
Marc’s (bio)perl course
Marc’s (bio)perl courseMarc’s (bio)perl course
Marc’s (bio)perl course
 
Perl bhargav
Perl bhargavPerl bhargav
Perl bhargav
 
Intro to PHP
Intro to PHPIntro to PHP
Intro to PHP
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
 
tutorial7
tutorial7tutorial7
tutorial7
 
tutorial7
tutorial7tutorial7
tutorial7
 

Recently uploaded

State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 

Recently uploaded (20)

State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 

Perl Scripting

  • 1. Perl Scripting M. Varadharajan Thiagarajar College of Engineering
  • 2. What We Will Cover?  What is Perl?  Creating and Executing Perl scripts  Standard Input and Output  Scalar Variables  Arrays  Hashes  Magic Variables: $_ and @ARGV
  • 3. What We Will Cover?  Control Structures  Looping Structures  File Operations  Split & Join  Using shell commands  Advanced Concepts you'll need to know
  • 4. What is Perl  Perl stands for − 'Practical Extraction and Reporting Language'  Developed by Larry Wall in 1987  Its called Perl and not PERL  High level Scripting Language  Dynamically Typed  Support for object oriented programming
  • 5. Some Advantages of Perl  Free and Open source  Fast, Flexible, Secure and Fun  Interpreted Language  Mature Community  Portability  Very good Documentation (POD)  Availability of Modules (CPAN)
  • 6. Typical Uses of Perl  Text processing  System administration tasks  CGI and web programming  Database interaction  Other Internet programming
  • 7. Hello World!  This script will print 'Hello World!'  Creation of the Perl Script: − Open your Text Editor (!MSWORD) − Type the following block & save #!/usr/bin/perl -w print “Hello World! n”;
  • 8. Hello World!  Some point to Note: − All Perl statements end with ';' − Add 'use strict;' if you're serious on the script − Comments in Perl start with '#' − The first line is known as Shebang line #!/usr/bin/perl -w
  • 9. Hello World!  Executing the script: − Call the interpreter with the script perl helloworld.pl or − Grant Executable Permissions & Execute Chmod a+x helloworld.pl ./helloworld.pl
  • 10. Scalar Variables  Place to store a single item of data  Scalar variables begin with '$'  Declaration is as follows (in strict mode) my $name;  Assigning values is similar to c $name = “varadharajan”; $total = 100; $cost = 34.34
  • 11. Standard Output  Print function is used  Syntax: print “some string”;  Example: (script prints “Perl is cool”) #/usr/bin/perl -w my $name = “perl”; print “$name is cool n”;
  • 12. Standard Input  Special operator '<>' is used  Synatx: $scalar = <STDIN>;  Example: (Get name and print it) #/usr/bin/perl -w print “Enter Name : ”; my $name = <STDIN>; print “Hello $name”;
  • 13. String Operations  Chomp: chomp($name); #removes the trailing new line  Concatenation: my $name = “Varadharajan ” . “Mukundan”;  Multiplication: $name = “hello ” x 3; #Assigns “hello hello hello” to name
  • 14. Arrays  Set of Scalar variables  Arrays start with '@'  Declaring Arrays: − Syntax: my @array_name=(value1,value2); − Example: my @list = ('varadharajan',99,'cool');
  • 15. Arrays  Accessing individual elements: − Syntax: $array_name[index]; #index starts with 0 − Example: print $list[1]; #prints 10
  • 16. Array Slices  Access a set of continuous elements in an array. − Syntax: @array_name[start_index .. end_index]; − Example: print @list[ 0 .. 2 ]; # Prints $list[0], $list[1], $list[2]
  • 17. Hashes  “Key – value ” Data Structure.  Keys present in a hash must be unique  Value may be same for multiple keys  Also commonly known as dictionaries
  • 18. Hashes  Initializing a Hash: − Syntax: my %hash_name = ( key => 'value'); − Example: my %students = ( name => 'varadharajan', age => 1 );
  • 19. Hashes  Accessing a Hash − Syntax: $hash_name{key_name}; − Example: print $student{name}; #prints varadharajan print $student{age}; #prints 18
  • 20. Hash Slices  Just like array slices  Syntax: @hash_name{'key1','key2'};  Example: print @student{'name','age'};
  • 21. Magic Variable: $_  Default variable for storing values, if no variables are manually specified.  Example: my @list = (1,2,4,34,5,223); foreach (@list) { print; } # prints the entire list
  • 22. Magic Variable: @ARGV  This Array is used to store the command line arguments  Example print $ARGV[0]; # when this script is executed like this # perl test1.pl text # it prints “text”
  • 23. Conditional control Structures  IF – ELSIF – ELSE statement: − Syntax: if (EXPR) {BLOCK} elsif (EXPR) {BLOCK} else {BLOCK} − Example: if($age==18) {print “Eighteen”;} elsif($age==19) {print “Nineteen”} else {print $age;}
  • 24. Looping Structures  While: $i = 0; while ($i < 10) { print $i; $i++; } # Prints 0123456789
  • 25. Looping Structures  For: for($i=0;$i<10;$i++) { print $i; } # prints 0123456789
  • 26. Looping Structures  Foreach: my @list = (“varadha”,19); foreach $value (@list) { print $value; } # prints the list
  • 27. File Operations  Opening a File: − Syntax: open(FILE_HANDLE , “[< |> |>>]File_Name”); − Example: open(MYFILE, “<myfile.txt”); − Available Modes: < - Read Mode > - Write Mode >> - Append Mode
  • 28. File Operations  Reading from a File: − Syntax: @array_name = <FILE_HANDLE>; − Example: @data = <MYFILE>; # Now @data contains the data presents in # File whose file handle is MYFILE
  • 29. File Operations  Writing to a File: − Syntax: print FILE_HANDLE “Text”; − Example: print MYFILE “This is the content”;
  • 30. File Operations  Closing a File: − Syntax: close(FILE_HANDLE); − Example: close(MYFILE);
  • 31. Split Function  Splits a scalar variable into arrays − Syntax: @array = split(PATTERN,EXPR); − Example: @words = split(/ /,$sentence);
  • 32. Join Function  Used to join all elements in an array to form a scalar − Syntax: $string = join(Joining_element,@arrays); − Example: $sentence = join(' ',@words);
  • 33. Executing Shell Commands  Makes us executed Shell commands from a Perl script − Syntax: system(command); − Example: $ls_data = system(“ls”);
  • 34. Advanced Concepts  Subroutines  Global and Local variables  Regular Expressions  OO programming  CPAN
  • 35. Perl Resources  Perl POD  Learning Perl from o'reilly  Programming Perl from o'reilly  Perl Beginners Mailing list at http://www.nntp.perl.org/group/perl.beginn ers/
  • 36. That's All Folks  Ping me at srinathsmn@gmail.com Thank You