SlideShare a Scribd company logo
1 of 5
Download to read offline
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";
}
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)
{
$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
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;
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";

More Related Content

What's hot

Unit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programmingUnit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programming
vrgokila
 

What's hot (20)

Features of c language 1
Features of c language 1Features of c language 1
Features of c language 1
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Loops c++
Loops c++Loops c++
Loops c++
 
Localization and Shared Preferences in android
Localization and Shared Preferences in androidLocalization and Shared Preferences in android
Localization and Shared Preferences in android
 
Super and final in java
Super and final in javaSuper and final in java
Super and final in java
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
 
System programming vs application programming
System programming vs application programmingSystem programming vs application programming
System programming vs application programming
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
Looping in C
Looping in CLooping in C
Looping in C
 
Java Basics
Java BasicsJava Basics
Java Basics
 
CP Handout#5
CP Handout#5CP Handout#5
CP Handout#5
 
Unit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programmingUnit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programming
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
 
scripting in Python
scripting in Pythonscripting in Python
scripting in Python
 

Similar to Basic perl programs

Perl courseparti
Perl coursepartiPerl courseparti
Perl courseparti
ernlow
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
rhshriva
 

Similar to Basic perl programs (20)

Perl bhargav
Perl bhargavPerl bhargav
Perl bhargav
 
Perl courseparti
Perl coursepartiPerl courseparti
Perl courseparti
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Programming in perl style
Programming in perl styleProgramming in perl style
Programming in perl style
 
Creating a compiler in Perl 6
Creating a compiler in Perl 6Creating a compiler in Perl 6
Creating a compiler in Perl 6
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
Simple perl scripts
Simple perl scriptsSimple perl scripts
Simple perl scripts
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
tutorial7
tutorial7tutorial7
tutorial7
 
tutorial7
tutorial7tutorial7
tutorial7
 
Tutorial perl programming basic eng ver
Tutorial perl programming basic eng verTutorial perl programming basic eng ver
Tutorial perl programming basic eng ver
 
perl_lessons
perl_lessonsperl_lessons
perl_lessons
 
perl_lessons
perl_lessonsperl_lessons
perl_lessons
 

Recently uploaded

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff
17thcssbs2
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
ashishpaul799
 

Recently uploaded (20)

Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdfPost Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
 
IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdfPost Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
 
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
 

Basic perl programs

  • 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";