SlideShare a Scribd company logo
1 of 8
SCALAR EXPRESSIONS
 Scalar data items are combined into expressions using operators.
$c=12;
$d=3+($c);
 1) ARITHMETIC OPERATORS
Perl provides usual arithmetic operator including auto-increment and auto-decrement.
Operator Example Result Definition
+ 7 + 7 = 14 Addition
- 7 - 7 = 0 Subtraction
* 7 * 7 = 49 Multiplication
/ 7 / 7 = 1 Division
** 7 ** 7 = 823543 Exponents
% 7 % 7 = 0 Modulus
$c=17;
$d=++$c; //increment then assign
$c=12;
$d=$c ++; //assign then increment
Binary arithmetic operation:
$a+=3;
$a=a+3;
 2)String Operators
In Perl most of the processing is done by using built-in functions
and regular expressions.
 Perl uses period (.) for concatenation of strings
 The other string operator is (x), used to replicate strings.
$a=“hello” x 3
$a=“hellohellohello”
$foo.= “ ”
 Arithmetic Operators used in String Context.
1. Auto-increment
This operator can be applied to a variable.
If a variable is assigned with string of letters and digits then auto
increment operation is applied on the string from rightmost character.
eg: $a=‘all12’;
print ++$a;
result: bmm23
2. Unary minus
If this is applied to string which starts with a plus or minus character,
then it returns the same string with opposite sign.
eg. $name=“sia”
-$name=“-sia”
 3) Comparison operator
Values of comparison is returned in numbers.
1--- if true and (“ ”) – if false
These are classified into two kinds. One for numbers and other for strings.
 Numbers: ==,!=,<,>,<=,>=,<=>(comparison operator)
 Strings: eq,ne,lt,gt,le,ge,cmp
 4)Logical operator
not ---- !
and ---- &&
or ---- ||
print “OKn” if $a<10 and $b<12;
 5) Conditional expressions
it is the one whose value is chosen from one of the alternatives at runtime
depending on the outcome of test.
test? True_exp:false_exp
eg: $a=($a<0)?0:$a;
CONTROL STRUCTURES
 A control structure is a block of programming that analyzes variables and chooses a
direction in which to go based on given parameters. The term flow control details the
direction the program takes (which way program control "flows").
 Blocks: It is a sequence of one or more statements enclosed in curly braces.
eg: {
$positive=1;
$negative=-1;
}
 Conditions: They make use of relational operators. It is a Perl expression which is
evaluated in Boolean context.
 If it evaluates to --- 0 or (“ “) --- condition is false, else it is treated as true.
 $total > 50 and $total <100
 A condition can be negated using ! Operator, we can specify that as
!($total > 50 and $total<100)
CONDITIONAL EXPRESSIONS
 Conditional Expressions should be in brackets.
 If-then-else statement:
if($total> 0){
print “$totaln”
} else {
print “wrong total ! n”
}
 If-elsif statement
if($total> 70) { $grade=“A”;} elsif($total > 56){ $grade =“B”;} else
{$grade=“C”); }
 Alternative to if-then-else statements are ‘conditional expression’ and using ‘or’
operator.
 In perl a single statement can be followed by a conditional modifier.
print “OKn” if $volts>=1.5;
REPETITION
 Testing loops and counting loops can be used for repetition mechanisms.
 Testing loops: while($a!=$b){
if($a > $b){
$a=$a-$b;
}else {
$b=$b-$a;
}
}
 An until loop statement in Perl programming language repeatedly executes a target
statement as long as a given condition is false.
 Syntax
 The syntax of an until loop in Perl programming language is −
 until(condition) { statement(s); }
 Here statement(s) may be a single statement or a block of statements.
 The condition may be any expression. The loop iterates until the condition becomes
true.
 When the condition becomes true, the program control passes to the line immediately
following the loop.
 $a+=2 while $a < $b; (and) $a+=2 until $a < $b;
 Although condition is specified after the written statement, it is evaluated before the
statement executed.
 Do loop:
It is built-in function rather than a syntactic construct.Overhere the condition is tested after
the execution of the block, so the block is executed at least once.
do{
...
}while $a!=$b;
 Counting Loops: They use same syntax as c
for($i=1;$i<=10;$i++){
$i_square=$i*$i;
$i_cube=$i**3;
print “ $it$i_squaret$i_cuben”;
}
 foreach $i (1..10) {
$i_square=$i*$i; $i_cube=$i**3;
print “ $it$i_squaret$i_cuben”; }
LOOP REFINEMENTS
 Perl provides three loop commands : last , next and redo . The last and next
command are similar to break and continue statements in c language.
 last breaks out of the loop and next forces the next iteration of a loop.
 Ex: to terminate input processing if a line contains ‘quit’ is read we write
while <STDIN> {
last if /quit/;
...
}
 The redo command repeats the current iteration from the beginning.
Output:
3 4 5 6 7

More Related Content

What's hot

Array,lists and hashes in perl
Array,lists and hashes in perlArray,lists and hashes in perl
Array,lists and hashes in perlsana mateen
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Aman Sharma
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cppNilesh Dalvi
 
Python Programming - Files & Exceptions
Python Programming - Files & ExceptionsPython Programming - Files & Exceptions
Python Programming - Files & ExceptionsOmid AmirGhiasvand
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsMayank Jain
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlsana mateen
 
Language Model (N-Gram).pptx
Language Model (N-Gram).pptxLanguage Model (N-Gram).pptx
Language Model (N-Gram).pptxHeneWijaya
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data typesPratik Devmurari
 
Syntax analyzer
Syntax analyzerSyntax analyzer
Syntax analyzerahmed51236
 
Learn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & MethodsLearn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & MethodsEng Teong Cheah
 
Linear regression with gradient descent
Linear regression with gradient descentLinear regression with gradient descent
Linear regression with gradient descentSuraj Parmar
 
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...Simplilearn
 

What's hot (20)

Array,lists and hashes in perl
Array,lists and hashes in perlArray,lists and hashes in perl
Array,lists and hashes in perl
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Python-Polymorphism.pptx
Python-Polymorphism.pptxPython-Polymorphism.pptx
Python-Polymorphism.pptx
 
Learning in AI
Learning in AILearning in AI
Learning in AI
 
Python Programming - Files & Exceptions
Python Programming - Files & ExceptionsPython Programming - Files & Exceptions
Python Programming - Files & Exceptions
 
PPT ON ALGORITHM
PPT ON ALGORITHMPPT ON ALGORITHM
PPT ON ALGORITHM
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perl
 
Language Model (N-Gram).pptx
Language Model (N-Gram).pptxLanguage Model (N-Gram).pptx
Language Model (N-Gram).pptx
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
 
Syntax analyzer
Syntax analyzerSyntax analyzer
Syntax analyzer
 
AI: Logic in AI
AI: Logic in AIAI: Logic in AI
AI: Logic in AI
 
Back propagation method
Back propagation methodBack propagation method
Back propagation method
 
Learn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & MethodsLearn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & Methods
 
Linear regression with gradient descent
Linear regression with gradient descentLinear regression with gradient descent
Linear regression with gradient descent
 
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
 

Viewers also liked

Unit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionsUnit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionssana mateen
 
Unit 1-perl names values and variables
Unit 1-perl names values and variablesUnit 1-perl names values and variables
Unit 1-perl names values and variablessana mateen
 
Unit 1-introduction to perl
Unit 1-introduction to perlUnit 1-introduction to perl
Unit 1-introduction to perlsana mateen
 
Unit 1-subroutines in perl
Unit 1-subroutines in perlUnit 1-subroutines in perl
Unit 1-subroutines in perlsana mateen
 
Unit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scriptingUnit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scriptingsana mateen
 
Unit 1-array,lists and hashes
Unit 1-array,lists and hashesUnit 1-array,lists and hashes
Unit 1-array,lists and hashessana mateen
 
Unit 1-introduction to scripts
Unit 1-introduction to scriptsUnit 1-introduction to scripts
Unit 1-introduction to scriptssana mateen
 
Soil mechanics practicals manual.(Jyoti Anischit)
Soil mechanics practicals manual.(Jyoti Anischit)Soil mechanics practicals manual.(Jyoti Anischit)
Soil mechanics practicals manual.(Jyoti Anischit)Jyoti Khatiwada
 
Fashion spread outfit 2
Fashion spread outfit 2Fashion spread outfit 2
Fashion spread outfit 2jp05064325
 
днз №22 фестиваль. джерело батьківських знань.
днз №22 фестиваль. джерело батьківських знань.днз №22 фестиваль. джерело батьківських знань.
днз №22 фестиваль. джерело батьківських знань.Анна Тараненко
 
3/13 announcement
3/13 announcement3/13 announcement
3/13 announcementtorraj01
 
Shortpdf 131208151245-phpapp02
Shortpdf 131208151245-phpapp02Shortpdf 131208151245-phpapp02
Shortpdf 131208151245-phpapp02Kener Ferreira
 
Planning booklet
Planning bookletPlanning booklet
Planning bookletben prudhoe
 
Seguridad del paciente karin
Seguridad del paciente karinSeguridad del paciente karin
Seguridad del paciente karinkarin pereyra
 
гунько н.в. майстер клас. фестиваль. джерело батьківських знань
гунько н.в. майстер клас. фестиваль. джерело батьківських знаньгунько н.в. майстер клас. фестиваль. джерело батьківських знань
гунько н.в. майстер клас. фестиваль. джерело батьківських знаньАнна Тараненко
 
Fashion spread outfit 3
Fashion spread outfit 3Fashion spread outfit 3
Fashion spread outfit 3jp05064325
 
Virvoitusjuomavero 7 pointtia
Virvoitusjuomavero 7 pointtiaVirvoitusjuomavero 7 pointtia
Virvoitusjuomavero 7 pointtiaPanimoliitto
 

Viewers also liked (19)

Unit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionsUnit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressions
 
Unit 1-perl names values and variables
Unit 1-perl names values and variablesUnit 1-perl names values and variables
Unit 1-perl names values and variables
 
Unit 1-introduction to perl
Unit 1-introduction to perlUnit 1-introduction to perl
Unit 1-introduction to perl
 
Unit 1-subroutines in perl
Unit 1-subroutines in perlUnit 1-subroutines in perl
Unit 1-subroutines in perl
 
Unit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scriptingUnit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scripting
 
Unit 1-array,lists and hashes
Unit 1-array,lists and hashesUnit 1-array,lists and hashes
Unit 1-array,lists and hashes
 
Unit 1-introduction to scripts
Unit 1-introduction to scriptsUnit 1-introduction to scripts
Unit 1-introduction to scripts
 
Soil mechanics practicals manual.(Jyoti Anischit)
Soil mechanics practicals manual.(Jyoti Anischit)Soil mechanics practicals manual.(Jyoti Anischit)
Soil mechanics practicals manual.(Jyoti Anischit)
 
Fashion spread outfit 2
Fashion spread outfit 2Fashion spread outfit 2
Fashion spread outfit 2
 
днз №22 фестиваль. джерело батьківських знань.
днз №22 фестиваль. джерело батьківських знань.днз №22 фестиваль. джерело батьківських знань.
днз №22 фестиваль. джерело батьківських знань.
 
Thriller pitch
Thriller pitchThriller pitch
Thriller pitch
 
3/13 announcement
3/13 announcement3/13 announcement
3/13 announcement
 
Shortpdf 131208151245-phpapp02
Shortpdf 131208151245-phpapp02Shortpdf 131208151245-phpapp02
Shortpdf 131208151245-phpapp02
 
Aplicación de las NIIF y NIC para PYMES
Aplicación de las NIIF y NIC para PYMESAplicación de las NIIF y NIC para PYMES
Aplicación de las NIIF y NIC para PYMES
 
Planning booklet
Planning bookletPlanning booklet
Planning booklet
 
Seguridad del paciente karin
Seguridad del paciente karinSeguridad del paciente karin
Seguridad del paciente karin
 
гунько н.в. майстер клас. фестиваль. джерело батьківських знань
гунько н.в. майстер клас. фестиваль. джерело батьківських знаньгунько н.в. майстер клас. фестиваль. джерело батьківських знань
гунько н.в. майстер клас. фестиваль. джерело батьківських знань
 
Fashion spread outfit 3
Fashion spread outfit 3Fashion spread outfit 3
Fashion spread outfit 3
 
Virvoitusjuomavero 7 pointtia
Virvoitusjuomavero 7 pointtiaVirvoitusjuomavero 7 pointtia
Virvoitusjuomavero 7 pointtia
 

Similar to Unit 1-scalar expressions and control structures

[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2yasir_cesc
 
Php Chapter 1 Training
Php Chapter 1 TrainingPhp Chapter 1 Training
Php Chapter 1 TrainingChris Chubb
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
Java Script Language Tutorial
Java Script Language TutorialJava Script Language Tutorial
Java Script Language Tutorialvikram singh
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3rohassanie
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptxrani marri
 
Programming Fundamentals lecture 7
Programming Fundamentals lecture 7Programming Fundamentals lecture 7
Programming Fundamentals lecture 7REHAN IJAZ
 
Control Structures
Control StructuresControl Structures
Control StructuresGhaffar Khan
 
C operators
C operatorsC operators
C operatorsGPERI
 

Similar to Unit 1-scalar expressions and control structures (20)

[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
 
Php Chapter 1 Training
Php Chapter 1 TrainingPhp Chapter 1 Training
Php Chapter 1 Training
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Perl_Part2
Perl_Part2Perl_Part2
Perl_Part2
 
Java Script Language Tutorial
Java Script Language TutorialJava Script Language Tutorial
Java Script Language Tutorial
 
What is c
What is cWhat is c
What is c
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
What is c
What is cWhat is c
What is c
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptx
 
C fundamental
C fundamentalC fundamental
C fundamental
 
Programming Fundamentals lecture 7
Programming Fundamentals lecture 7Programming Fundamentals lecture 7
Programming Fundamentals lecture 7
 
Control Structures
Control StructuresControl Structures
Control Structures
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
lesson 2.pptx
lesson 2.pptxlesson 2.pptx
lesson 2.pptx
 
Programming in C
Programming in CProgramming in C
Programming in C
 
C operators
C operatorsC operators
C operators
 

More from sana mateen

More from sana mateen (19)

Files
FilesFiles
Files
 
PHP Variables and scopes
PHP Variables and scopesPHP Variables and scopes
PHP Variables and scopes
 
Php intro
Php introPhp intro
Php intro
 
Php and web forms
Php and web formsPhp and web forms
Php and web forms
 
Mail
MailMail
Mail
 
Files in php
Files in phpFiles in php
Files in php
 
File upload php
File upload phpFile upload php
File upload php
 
Regex posix
Regex posixRegex posix
Regex posix
 
Encryption in php
Encryption in phpEncryption in php
Encryption in php
 
Authentication methods
Authentication methodsAuthentication methods
Authentication methods
 
Xml schema
Xml schemaXml schema
Xml schema
 
Xml dtd
Xml dtdXml dtd
Xml dtd
 
Xml dom
Xml domXml dom
Xml dom
 
Xhtml
XhtmlXhtml
Xhtml
 
Intro xml
Intro xmlIntro xml
Intro xml
 
Dom parser
Dom parserDom parser
Dom parser
 
Uses for scripting languages,web scripting in perl
Uses for scripting languages,web scripting in perlUses for scripting languages,web scripting in perl
Uses for scripting languages,web scripting in perl
 
Perl names values and variables
Perl names values and variablesPerl names values and variables
Perl names values and variables
 
Data structure in perl
Data structure in perlData structure in perl
Data structure in perl
 

Recently uploaded

Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 

Recently uploaded (20)

Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 

Unit 1-scalar expressions and control structures

  • 1. SCALAR EXPRESSIONS  Scalar data items are combined into expressions using operators. $c=12; $d=3+($c);  1) ARITHMETIC OPERATORS Perl provides usual arithmetic operator including auto-increment and auto-decrement. Operator Example Result Definition + 7 + 7 = 14 Addition - 7 - 7 = 0 Subtraction * 7 * 7 = 49 Multiplication / 7 / 7 = 1 Division ** 7 ** 7 = 823543 Exponents % 7 % 7 = 0 Modulus $c=17; $d=++$c; //increment then assign $c=12; $d=$c ++; //assign then increment Binary arithmetic operation: $a+=3; $a=a+3;
  • 2.  2)String Operators In Perl most of the processing is done by using built-in functions and regular expressions.  Perl uses period (.) for concatenation of strings  The other string operator is (x), used to replicate strings. $a=“hello” x 3 $a=“hellohellohello” $foo.= “ ”  Arithmetic Operators used in String Context. 1. Auto-increment This operator can be applied to a variable. If a variable is assigned with string of letters and digits then auto increment operation is applied on the string from rightmost character. eg: $a=‘all12’; print ++$a; result: bmm23 2. Unary minus If this is applied to string which starts with a plus or minus character, then it returns the same string with opposite sign. eg. $name=“sia” -$name=“-sia”
  • 3.  3) Comparison operator Values of comparison is returned in numbers. 1--- if true and (“ ”) – if false These are classified into two kinds. One for numbers and other for strings.  Numbers: ==,!=,<,>,<=,>=,<=>(comparison operator)  Strings: eq,ne,lt,gt,le,ge,cmp  4)Logical operator not ---- ! and ---- && or ---- || print “OKn” if $a<10 and $b<12;  5) Conditional expressions it is the one whose value is chosen from one of the alternatives at runtime depending on the outcome of test. test? True_exp:false_exp eg: $a=($a<0)?0:$a;
  • 4. CONTROL STRUCTURES  A control structure is a block of programming that analyzes variables and chooses a direction in which to go based on given parameters. The term flow control details the direction the program takes (which way program control "flows").  Blocks: It is a sequence of one or more statements enclosed in curly braces. eg: { $positive=1; $negative=-1; }  Conditions: They make use of relational operators. It is a Perl expression which is evaluated in Boolean context.  If it evaluates to --- 0 or (“ “) --- condition is false, else it is treated as true.  $total > 50 and $total <100  A condition can be negated using ! Operator, we can specify that as !($total > 50 and $total<100)
  • 5. CONDITIONAL EXPRESSIONS  Conditional Expressions should be in brackets.  If-then-else statement: if($total> 0){ print “$totaln” } else { print “wrong total ! n” }  If-elsif statement if($total> 70) { $grade=“A”;} elsif($total > 56){ $grade =“B”;} else {$grade=“C”); }  Alternative to if-then-else statements are ‘conditional expression’ and using ‘or’ operator.  In perl a single statement can be followed by a conditional modifier. print “OKn” if $volts>=1.5;
  • 6. REPETITION  Testing loops and counting loops can be used for repetition mechanisms.  Testing loops: while($a!=$b){ if($a > $b){ $a=$a-$b; }else { $b=$b-$a; } }  An until loop statement in Perl programming language repeatedly executes a target statement as long as a given condition is false.  Syntax  The syntax of an until loop in Perl programming language is −  until(condition) { statement(s); }  Here statement(s) may be a single statement or a block of statements.  The condition may be any expression. The loop iterates until the condition becomes true.  When the condition becomes true, the program control passes to the line immediately following the loop.  $a+=2 while $a < $b; (and) $a+=2 until $a < $b;  Although condition is specified after the written statement, it is evaluated before the statement executed.
  • 7.  Do loop: It is built-in function rather than a syntactic construct.Overhere the condition is tested after the execution of the block, so the block is executed at least once. do{ ... }while $a!=$b;  Counting Loops: They use same syntax as c for($i=1;$i<=10;$i++){ $i_square=$i*$i; $i_cube=$i**3; print “ $it$i_squaret$i_cuben”; }  foreach $i (1..10) { $i_square=$i*$i; $i_cube=$i**3; print “ $it$i_squaret$i_cuben”; }
  • 8. LOOP REFINEMENTS  Perl provides three loop commands : last , next and redo . The last and next command are similar to break and continue statements in c language.  last breaks out of the loop and next forces the next iteration of a loop.  Ex: to terminate input processing if a line contains ‘quit’ is read we write while <STDIN> { last if /quit/; ... }  The redo command repeats the current iteration from the beginning. Output: 3 4 5 6 7