TYPES OF CONTROL STRUCTURES SEEN IN PERL.ppt

dhanushprabhakarv 7 views 15 slides Jul 28, 2024
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

Control structures in perl


Slide Content

CONTROL STRUCTURES

Control Structures
Aprogramisacollectionofstatements.Aftertheprogram
executesonestatement,it"moves"tothenextstatementand
executesthatone.
The execution flow is a simple sequence.
Example:
$number1 = ‘ATCG’;
$number2 = ‘GGG’;
$sum = $number1.$number2;
Print $num;
Output: ?

Control structures:
if, else, elsif, switch, while, until, do…while, for andfor…each.
1. if

Flow of Control –‘if’

Flow of Control –‘if-else’

Theconditioninanifstatementcanbeanyexpression.
Theconditionisusuallyonethatisbuiltfromrelationalor
logicaloperators.
Forexample,
$x>$y
isaconditionthatistrueifthevalueof$xisgreaterthanthe
valueof$y
RelationalOperators:operatorsthatcompare2expressions

Numeric relational operators

Comparing Strings

1. Sample Program using ‘if’ and ‘if else’
$sequence="ATGC";
if(defined $seq)
{
print "defined";
}
else
{
print "not defined";
}
Output: ???

2. Sample Program using ‘if’ and ‘if else’
print "Enter 2 numbers, one per line\n";
$a = <STDIN>;
$b = <STDIN>;
if
( $a < $b ) {
print "$a then $b\n";
}
else
{
print "$b then $a\n";
}

elsif

print "Enter 2 numbers, one per line\n";
$a = <STDIN>;
$b = <STDIN>;
if
( $a < $b ) {
print "$a is less than $b\n";
}
elsif
( $b < $a ) {
print "$b is less than $a\n";
}
else
{
print "The numbers are equal.\n";
}
1. Sample program using ‘elsif’
Tags