the document contains the most basic programs used in perl programming. It illustrates the basic operator types used in this particular programming language. It will be very useful to implement basic scripting language.
1. BASIC PERL PROGRAMS
PROGRAM #1
TO IMPLEMENT THE BASIC SCRIPTING CONCEPTS
#!/usr/bin/perl-x
#a silly script to output text
print”hello everyonen”;
PROGRAM #2
#!/usr/bin/perl-x
#to print strings and also learn the function of variables
print”enter your name:”;
$name=<>;
$string=”Welcome to basics of perl programming”;
print”Hello $namen”;
print$string;
PROGRAM #3
IF-ELSE Example
my $k =88-87;
if($k)
{
print "OKn";
}
else
{
print "NOn";
2. }
PROGRAM#4
WHILE Example
print "enter your university grade for evaluation";
my $n = <>;
chomp($n);
while($n<=10)
{
print "$nn";
$n++;
};
print "donen";
IF-ELSIF-ELSE Example
my($grade,$evaluation);
print "Enter student grade(between 0-100)";
$grade=<>;
chomp($grade);
if($grade>=0 and $grade<=35)
{
$evaluation="failed";
}
elsif($grade>35 and $grade<=50)
{
$evaluation="bad";
}
elsif($grade>50 and $grade<=70)
3. {
$evaluation="good";
}
elsif($grade>70 and $grade<=100)
{
$evaluation="Very good";
}
else
{
$evaluation="Invalid output";
}
print "Evaluation:$evaluationn";
PROGRAM #5
UNTIL Example
print "enter a number";
my $n =<>;
chomp($n);
until($n>10)
{
print "$nn";
$n++;
};
print "donen";
PROGRAM #6
DO-UNTIL Example
4. my($num,$uni);
do
{
print "please enter no. of meters of cloth given for stitching";
$num=<>;
chomp($num);
}
until($num>0 and $num% 3 == 0);
$uni= $num/3;
print"no. of uniforms that can be stitched: $unin";
PROGRAM #7
STRING MANIPULATION
$DNA1 = 'ACGGGAGGACGGGAAAATTACTACGGCATTAGC';
$DNA2 = 'ATAGTGCCGTGAGAGTGATGTAGTA';
# Print the DNA onto the screen
print "Here are the original two DNA fragments:nn";
print $DNA1, "n";
print $DNA2, "nn";
# Concatenate the DNA fragments into a third variable and print them
# Using "string interpolation"
$DNA3 = "$DNA1$DNA2";
print "Here is the concatenation of the first two fragments (version 1):nn";
print "$DNA3nn";
# An alternative way using the "dot operator":
# Concatenate the DNA fragments into a third variable and print them
$DNA3 = $DNA1. $DNA2;
5. print "Here is the concatenation of the first two fragments (version 2):nn";
print "$DNA3nn";
print "Here is the concatenation of the first two fragments (version 3):nn";
print $DNA1, $DNA2, "n";
exit;
PROGRAM #8
TRANSCRIPTION OF DNA
$DNA='ACGGGGTAAACCCGATC';
#Print the DNA onto the screen
print"Here is the starting DNA:nn";
print"$DNAnn";
#Transcribe the DNA to RNA by substituting all T's with U's
$RNA=$DNA;
$RNA=~s/T/U/g;
#Print the RNA onto the screen
print"Hereis the result of transcribing the DNA to RNA:nn";
print"$RNAn";