Professional Documents
Culture Documents
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
LIST OF EXPERIMENTS
1. Basic UNIX Commands
2. Working with vi editor
3. Working with emacs editors
4. Advanced UNIX Utilities
5. Creating a Bioinformatics directory
6. Simple Perl Program (Operators)
7. Use of <STDIN>
8. Chop and Chomp Operators
9. Control Structures:
a) If‐If else statements
b) While statement
c) foreach and Until Loops
10. Subroutines, Subroutines using array and special variables
11. Random Number Generation
12. Simple programs using File Functions
13. Hash Traversal Functions
14. Command Line Arguments
15. Setuid / setgid Perl Scripts
16. Creating a static HTML file by a Perl Program
BI0313 / Perl Programming Laboratory 5
1 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 1 DATE:
BASIC UNIX COMMANDS
AIM: To execute all the basic commands in UNIX
PROCEDURE: Open Terminal and execute all the following Basic UNIX commands:
Command name : mkdir
Description : Creating a directory
Options : Nil
Example : >mkdir directory name
Output : /home/username/directoryname
Command name : cd
Description : change directory
Options : cd..‐ move one level down
cd/‐ to go to the root directory
cd~‐ to go to the home directory
cd../..‐ move two levels up
Example : >cd directory
Output : /home/username/directory
Command name : ls
Description : listing contents of the directory
Options : ls‐l‐ listing the contents of the file in list fashion
ls‐lc‐ listing the contents of the file in column of fashion
ls‐t‐ listing the contents of directory according to time
ls‐x‐ listing the contents of directory in rows
ls‐m‐ listing the contents of directory separated by commas
ls‐R‐ recursively displaying the files and directories
Example : >ls sequences
Output : analysis assembly
BI0313 / Perl Programming Laboratory 5
2 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
Command name : mv
Description : moving or renaming a file or a directory
: mv*.seq/user.sequences‐ all files with .seq extensions are moved to
user directory
mv‐i94H10.seq‐ ignores the case
mv94{h,H}10.seq‐ it is used to rename the file
Example : >mvAC 078839.txt94h10.seq
Options : 94H10.seq
Command name : cp
Description : copying a file
Options : Nil
Example : >cp Ac(4H10.seq{,.bak}
Output : Adds extension.bak to all sequence files
Command name : head and tail
Description : used to display top few or bottom few lines of a line
Options : Nil
Example : >head 94H10.seq
>tail 94H10.seq
Output : It displays the first and last ten lines of 94H10.seq
Command name : cat
Description : create, view and append or change the contents of a file
Options : Nil
Example : cat>new
Output : a new file is created
Command name : rm and rmdir
Description : removing a file or a directory
Options : nil
Example : rm‐r seq x
Output : removes all files starting with seq(recursive deletion)
BI0313 / Perl Programming Laboratory 5
3 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
Command name : find
Description : searching a particular file or a directory
Options : nil
Example : find.‐name “seqchr*”
Output : finds all the files starting with seqchr* as a part of it
Command name : more
Description : displays the contents of the file
Options : nil
Example : more 94H10.seq
Output : prints contents of the file 94H10.seq
Command name : chmod
Description : used to change the permissions of a file
Options : nil
Example : chmod 777 file.txt
Output : gives read, write and execute permissions to user, group and world
Command name : ps
Description : process tracking (to find how many processes are running)
Options : nil
Example : >ps
Output : PID TTY TIME COMMAND
Command name : kill
Description : used to stop the process
Options : nil
Example : >file.txt
Output : it the stops the processes of file.txt
Command name : tar
Description : related files are grouped together
BI0313 / Perl Programming Laboratory 5
4 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
Options : tar –cvffile1.tar
tar –tvf
tar‐xvf
tar‐cvf
Example : tar –cvf*.seq
Output : archive seq files in the current directory
MISCELLANEOUS COMMANDS:
Command name : gzip/compress and gunzip/uncompress
Description : gzip –file is compressed to size smaller than compress.
Compress –used to compress file but size greater than that obtained by gzip.
Uncompress – used to uncompress file but size smaller than that obtained by gunzip.
Options : nil
Example : >gzip test.tar
>compress test.tar
Output : test.tar.gz
Test.tar.z
RESULT: The Basic UNIX Commands were thus executed and the output as noted.
BI0313 / Perl Programming Laboratory 5
5 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 2 DATE:
Vi EDITOR COMMANDS
AIM: To study the various UNIX commands
PROCEDURE: Open Terminal and open vi editor. Try out the following commands:
Saving and Quitting:
:q – quit without saving
:q! – quit without saving even changes are made
:w – save and continue editing
:wq – save and quit
:zz – write file only if changes were made and quit
:x – same function as zz
Moving around text:
h ‐ move cursor one character left
i ‐ move cursor one character right
k ‐ move cursor up one line
j ‐ move cursor down one line
G ‐ move to end of file
H ‐ move to top line visible on screen
L ‐ move to last line visible on screen
M ‐ move to middle line visible on screen
w ‐ move forward word by word
b ‐ move backward word by word
W ‐ move forward one word ignoring punctuation
e ‐ move end of word
O ‐ move to beginning of line
$ ‐ move to end of file
BI0313 / Perl Programming Laboratory 5
6 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
Changing, Deleting, and Substituting text
cc ‐ change a single line
C ‐ change text from cursor to end of line
x ‐ delete cw – change a single word, single character under cursor
X ‐ delete single character before cursor
dw ‐ delete a word
d{} ‐ delete upto next paragraph
dd ‐ delete current line
D ‐ delete from cursor to end of line
dL ‐ delete upto last line of screen
dG ‐ delete to end of line
j ‐ join two lines
rx ‐ replace one character with x
R ‐ override characters
s ‐ substitute a character
S ‐ substitute a line
u ‐ undo last change
U ‐ restore current line
Scrolling and Indenting Text:
<ctrl>f – scroll forward one window
<ctrl>b – scroll back one window
>> ‐ shift current line forward one indent width
<< ‐ shift current line back one indent width
Finding and Searching for text:
fx – find first occurrence of character x ahead of cursor
Fx – find first occurrence of x behind cursor
Cutting and Pasting:
Y – copy correct manual
p – put deleted text after or below cursor
P ‐ put deleted text before or after cursor
RESULT: The vi editor commands were successfully executed and the output was noted.
BI0313 / Perl Programming Laboratory 5
7 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 3 DATE:
EMACS EDITOR COMMANDS
AIM: To study the various commands in emacs editor
PROCEDURE:
1. Open Terminal and create an emacs file using the command, #emacs <filename>
2. Insert text using the emacs editor
3. Perform the following operations using the various emacs editor commands and
note the output
ESSENTIAL EMACS COMMANDS:
Ctrl + A: Move to the beginning of the line
Ctrl + E: Move to the end of the line
Ctrl + S: Start search text
Ctrl + d: Delete single character in a line
Ctrl + K: Delete entire line upto cursor
Delete: Delete character before cursor
Ctrl + _: Undo last action
Ctrl + X/ Ctrl + S: Save current file and exit
Ctrl + X/ Ctrl + C: Exit emacs without saving
Home: Go to the beginning of the document
End: Go to the end of the document
BI0313 / Perl Programming Laboratory 5
8 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
MISCELLANEOUS EMACS COMMANDS:
Ctrl + P: Move to the previous line
Ctrl + N: Move to the next line
Ctrl + F: Move forward one character
Ctrl + B: Move backwards one character
Ctrl + V: Scroll down one page
Esc V: Scroll up one page
Esc F: Move ahead word by word
Esc B: Move backward word by word
Esc A: Move to the beginning of the sentence
Esc E: Move to the end of the sentence
OUTPUT:
The commands were executed on emacs editor and changes were observed.
RESULT: The basic emacs editor commands were successfully executed and the output was
noted.
BI0313 / Perl Programming Laboratory 5
9 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 4 DATE:
ADVANCED UNIX UTILITIES
AIM: To study the syntax and usage of various UNIX utilities such as grep and uniq.
PROCEDURE:
Open Terminal and perform the advanced commands (Utilities) described below:
1. grep
Utility name : grep
Description : global search for regular expressions
Options : searches given keywords and prints files containing it
Example : >grep –v ase genes.txt ! more
Output : all lines that do not carry the string ‘ase’ are printed out with the –v option
2. wc
Utility name : wc
Description : gives number of lines, words and characters in a file
Options : wc‐1‐ gives number of lines
wc‐w‐ gives the number of words
wc‐c‐ gives the number of characters
Example : >wc mydetails.txt
Output : 4 18 40
3. uniq
Utility name : uniq
Description : deletes the repeted text in a file
Options : uniq –c‐ gives the text along with the number of times they are present
Example : >uniq test.txt
BI0313 / Perl Programming Laboratory 5
10 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
Output : This
Is
Some
Repeated
Text
4. sort
Utility name: …
Description : used for sorting the contents of a file
Options : sort ‐r –to sort in descending
sort ‐f –ignores case separator
sort ‐t –ignores files separator
sort ‐M‐ orders based on month
Example : >sort test.txt
Output : Is
Some
Repeated’
Text
This
5. awk
Utility name : awk
Description : helps to print contents of file based on given conditions
Options : nil
Example : >cat>test.txt
1 one a
2 two b
3 three c
>awk ‘{print $1} test.txt
BI0313 / Perl Programming Laboratory 5
11 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
Output : 1
2
3
RESULT: The advanced UNIX Utility commands were successfully executed.
BI0313 / Perl Programming Laboratory 5
12 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 5 DATE:
CREATING A BIOINFORMATICS DIRECTORY
AIM: To create a Bioinformatics Directory Structure to study the basic UNIX commands.
Structure:
Root
Home
Sequences
Assembly Analysis
Human Mouse Rice Human Mouse Rice
Ch22 Chr22 Chr5 Chr22 Chr22 Chr5
Chr10 Chr4 Chr10 Chr10
Chr10 Chr4
BI0313 / Perl Programming Laboratory 5
Chr5 13 th semester
Chr5 Chr5
Chr5
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
PROCEDURE :
1. Open terminal (Shell)
2. Create a Bioinformatics Directory using the following commands to make files
and folders in the main directory
COMMANDS:
$ mkdir sequences
$ cd sequences
$ mkdir assembly
$ cd assembly
$ mkdir human
$ mkdir mouse
$ mkdir rice
$ cd human
$ mkdir chr22
$ cd chr22
$ mkdir chr10
$ cd chr10
$ mkdir chr5
$ cd chr5
$ cd..
$ cd..
$ cd..
$ cd mouse
$ mkdir chr22
$ cd chr22
$ mkdir chr10
$ cd chr10
$ mkdir chr5
$ cd chr5
$ cd..\..
$ cd..
$ cd rice
$ mkdir chr5
BI0313 / Perl Programming Laboratory 5
14 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
$ cd chr5
$ mkdir chr4
$ cd..\..
$ cd..
$ cd analysis
$ mkdir human
$ mkdir mouse
$ mkdir rice
$ cd human
$ mkdir chr22
$ cd chr22
$ mkdir chr10
$ mkdir chr5
$ cd chr5
$ cd..
$ cd..
$ cd..
$ cd mouse
$ mkdir chr22
$ cd chr22
$ mkdir chr10
$ cd chr10
$ mkdir chr5
$ cd chr5
$ cd..\..
$ cd..
$ cd rice
$ mkdir chr5
$ cd chr5
$ mkdir chr4
$ cd~
RESULT: The Bioinformatics directory was successfully created using various UNIX
Commands.
BI0313 / Perl Programming Laboratory 5
15 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 6 DATE:
SIMPLE PERL PROGRAM
AIM: To illustrate the basic structure of Perl program.
PROCEDURE:
1. Open Terminal, create a file using VI Editor and type in the program with .pl as
extension
2. Compile and execute using #perl <filename.pl> command and note the output
PROGRAM:
$aminoacid="methionine";
$protein="lysin";
print "aminoacid=$aminoacid\n";
print"protein=$protein\n";
$msg="welcome to perl
programming
for bioinformatics";
print "$msg\n";
OUTPUT:
RESULT: A simple perl program using print function was successfully executed
BI0313 / Perl Programming Laboratory 5
16 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
SIMPLE SCALAR PROGRAM
AIM: To illustrate the simple scalar function of Perl program
PROCEDURE:
1. Open Terminal, create a file using VI Editor and type in the program with .pl as
extension
2. Compile and execute using #perl <filename.pl> command and note the output
PROGRAM:
$a=15, $b=5;
$c=$a+$b;
$d=$a*$b;
$e=$a/$b;
print "a is=$a\n";
print"b=$b\n";
print"the sum of two no.:$c\n";
print"the multiplication:$d\n";
print"the division:$e\n";
OUTPUT:
RESULT: The simple perl program that uses scalar was successfully executed and the
output was saved
BI0313 / Perl Programming Laboratory 5
17 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EXP. NO: 7 DATE:
PERL SCRIPT USING <STDIN>
AIM: To illustrate the use of <STDIN>
PROCEDURE:
1. Open Terminal, create a file using VI Editor and type in the program with .pl as
extension
2. Compile and execute using #perl <filename.pl> command and note the output
PROGRAM:
print "Enter any number: ";
$a=<STDIN>;
print "Enter another number: ";
$b=<STDIN>;
$c=$a+$b;
print "Addition of the numbers is: $c \n";
OUTPUT:
RESULT: The perl script that uses a <STDIN> Standard Input from user was successfully
executed
BI0313 / Perl Programming Laboratory 5
18 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 8 DATE:
CHOP and CHOMP OPERATORS
AIM: To illustrate two scalar variables one with \n character and other with only
characters.
PROCEDURE:
1. Open Terminal, create a file using VI Editor and type in the program with .pl as
extension
2. Compile and execute using #perl <filename.pl> command and note the output
PROGRAM:
$enzyme="Ribonuclease\n";
chomp($enzyme);
print"The gene after chomp function is :$enzyme\n";
$enzyme2=”Helicase”;
chop($enzyme2);
print "the gene after chop operator is :$enzyme2\n";
print "Enter an enzyme name:”;
$enzyme1=<STDIN>;
chomp($enzyme1);
print "The entered gene after chomp function is:$enzyme1\n\n";
OUTPUT:
RESULT: The perl program that illustrates the Chop and Chomp operators was successfully
executed
BI0313 / Perl Programming Laboratory 5
19 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 9(a) DATE:
PERL CONTROL STATEMENTS
IF STATEMENT
AIM: To illustrate the if statement
PROCEDURE:
1. Open Terminal, create a file using VI Editor and type in the program with .pl as
extension
2. Compile and execute using #perl <filename.pl> command and note the output
PROGRAM:
print "Enter a number below 10: ";
$a=<STDIN>;
if($a<10){
print "You entered correctly! \n";
}
if($a>=10){
print "You entered it wrong! \n";
}
OUTPUT:
RESULT: The perl program that illustrated the if statement was successfully executed
BI0313 / Perl Programming Laboratory 5
20 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
IFELSE STATEMENT
AIM: To illustrate the use of if‐else statement.
PROCEDURE:
1. Open Terminal, create a file using VI Editor and type in the program with .pl as
extension
2. Compile and execute using #perl <filename.pl> command and note the output
PROGRAM:
print “Enter a number below 10: “;
$a=<STDIN>;
if($a<10){
print “You entered correctly! \n”;
}
else{
print ”You entered it wrong! \n”;
}
OUTPUT:
RESULT: The perl program that illustrates the ifelse statement was successfully executed
BI0313 / Perl Programming Laboratory 5
21 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 9(b) DATE:
WHILE LOOP
AIM: To illustrate the use of WHILE loop.
PROCEDURE:
1. Open Terminal, create a file using VI Editor and type in the program with .pl as
extension
2. Compile and execute using #perl <filename.pl> command and note the output
PROGRAM:
print "Program to print first 10 natural numbers \n";
$i=1;
while($i<=10){
print "$i \n";
$i++;
}
OUTPUT:
RESULT: The perl program that illustrates the while loop was successfully executed
BI0313 / Perl Programming Laboratory 5
22 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
DOWHILE LOOP
AIM: To illustrate the use of DO‐WHILE loop.
PROCEDURE:
1. Open Terminal, create a file using VI Editor and type in the program with .pl as
extension
2. Compile and execute using #perl <filename.pl> command and note the output
PROGRAM:
print "Program to print first 10 natural numbers \n";
$i=1;
do{
print "$i \n";
$i++;
}
while($i<=10);
OUTPUT:
RESULT: The perl program that illustrates the dowhile statement was successfully
executed
BI0313 / Perl Programming Laboratory 5
23 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 9(c) DATE:
FOREACH LOOP
AIM: To illustrate the use of FOREACH LOOP.
PROCEDURE:
1. Open Terminal, create a file using VI Editor and type in the program with .pl as
extension
2. Compile and execute using #perl <filename.pl> command and note the output
PROGRAM:
@names=qw(Bhupendra Rahul Rehan);
$count=1;
foreach $names(@names){
print "$count $names \n";
$count++;
}
OUTPUT:
RESULT: The perl program that illustrates the foreach loop was successfully executed
BI0313 / Perl Programming Laboratory 5
24 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
UNTIL
AIM: To illustrate the UNTIL Loop
PROCEDURE:
1. Open Terminal, create a file using VI Editor and type in the program with .pl as
extension
2. Compile and execute using #perl <filename.pl> command and note the output
PROGRAM:
print "Program to print first 10 natural numbers \n";
$i=1;
until($i>10){
print "$i \n";
$i++;
}
OUTPUT:
RESULT: The perl program that illustrates the Until Loop was successfully executed
BI0313 / Perl Programming Laboratory 5
25 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 10 DATE:
SUBROUTINES
AIM: To study and execute subroutines (sub programs) that is called in the main program
# Any variable created outside a subroutine is Global and can be accessed inside
subroutines.
PROCEDURE:
1. Open Terminal and type the program in vi editor using subrout.pl command.
2. Execute the program and note the output.
PROGRAM:
print “Enter degrees in Farenheit :\n”;
$degf = <STDIN>;
Chop($degf);
print Celsius();
sub print celsius{
$degc = ($degf – 32)*(5/9);
print “$degf degree farenheit is $degc degree celsius\n”;
}
OUTPUT:
BI0313 / Perl Programming Laboratory 5
26 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
Subroutine using array and special variables
PROGRAM:
print "Enter any 5 numbers : \n";
$_= <>;
@nums = split();
print "The sum is ",&sum_arr(@nums), "\n";
sub sum_arr{
my(@val) = @_;
my(@sum) = 0;
foreach $i(@val){
$sum = $sum + $i;
}
return ($sum);
}
OUTPUT:
RESULT: The programs that showed Subroutines and the use of arrays and special
variables in subroutines was successfully executed and the output was saved
BI0313 / Perl Programming Laboratory 5
27 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 11 DATE:
RANDOM NUMBER GENERATION
AIM: To generate a random integer/number using the rand() function.
PROCEDURE:
• Open Terminal and type the program in vi editor, using vi rand.pl command.
• Execute and run to obtain a random number, use Ranges and obtain integers.
• Run by using perl rand.pl command,
PROGRAM:
Random number between 0 and 1 :
use strict;
use warnings;
my $my_rand_num = rand();
print $my_rand_num.”\n”;
OUTPUT:
Range of numbers:
use strict;
use warnings;
my $range = 100;
$rand_num = rand($range);
print $rand_num.”\n”;
BI0313 / Perl Programming Laboratory 5
28 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
OUTPUT:
A random integer with a range:
use strict;
use warnings;
my $range = 50;
my $min = 100;
my $rand_num = int(rand($range)) + $min;
print $rand_num.”\n”;
OUTPUT:
RESULT: The perl program that illustrates the rand() function to generate random
numbers was successfully executed
BI0313 / Perl Programming Laboratory 5
29 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 12 DATE:
PERL PROGRAMMING using FILE FUNCTIONS
AIM: To study and execute a Perl program that uses functions to open and edit files.
PROCEDURE:
1. Open Terminal and type the program in vi editor using file.pl command.
2. Execute the program Perl file.pl and note the output.
PROGRAM:
$path = "G:\Documents\123.seq";
open(HANDLE, $path) or die "Error opening $path : $!";
$path = <HANDLE>;
$a = ($path = ~tr/A//);
$t = ($path = ~tr/T//);
$g = ($path = ~tr/G//);
$c = ($path = ~tr/C//);
print "A is $a";
print "T is $t";
print "G is $g";
print "C is $c";
$total = $a + $t +$g +$c;
print "Total number of nucleotides is $total \n";
BI0313 / Perl Programming Laboratory
30 5th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
$gc = ((($g + $c)/ $total) *100);
print “GC content is :$gc \n”;
close(HANDLE);
OUTPUT:
Formatting output with printf
%.1f: To get one digit after the decimal (long float).
ln program,
printf “GC content is :%.1f%\n”,$gc;
RESULT: The perl program that uses the functions such as open to view and edit files was
successfully executed and the output was noted
BI0313 / Perl Programming Laboratory 5
31 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 13 DATE:
HASH TRAVERSAL FUNCTIONS
Hashes are denoted by %
AIM:
To study and execute programs that shows the hash functions.
PROCEDURE:
3. Open Terminal and type the program in vi editor using hashes.pl command.
4. Execute the program and note the output.
PROGRAM:
To traverse the hash and extract elements:
print"Program to print contents of a hash\n";
%coins=("Quarter",25,"Dime",10,"Nickel",5);
print"Contents of the hash are:", %coins;
OUTPUT:
Printing elements based on their key:
print “Program to print elements based on the key”;
%coins = (“Quarter”, 25, “Dime”, 10, “Nickel”, 5);
foreach $key(%coins){
print “{$key} \n”;
}
BI0313 / Perl Programming Laboratory 5
32 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
OUTPUT:
To print the hash size:
print “Program to print hash size\n”;
%coins = (“Quarter”, 25, “Dime”, 10, “Nickel”, 5);
print “The hash size is : “, scalar keys %coins;
OUTPUT:
To add element to the hash:
%coins = ("Quarter", 25, "Dime", 10, "Nickel", 5);
print "Contents of the hash: ", %coins;
$coins {"Penny"} = 1;
print "\nAfter addition: ",%coins;
BI0313 / Perl Programming Laboratory 5
33 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
OUTPUT:
To remove element from hash:
%coins = ("Quarter", 25, "Dime", 10, "Nickel", 5);
print "Contents of the hash: ", %coins;
delete ($coins {"Quarter"});
print "\nAfter deletion: ",%coins;
OUTPUT:
To sort elements in the hash:
%coins = ("Quarter", 25, "Dime", 10, "Nickel", 5);
foreach $key (sort keys %coins){
print "{$key} \n";
}
OUTPUT:
RESULT: All the perl programs that illustrated the hash traversal functions was
successfully executed
BI0313 / Perl Programming Laboratory 5
34 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 14 DATE:
COMMAND LINE ARGUMENTS
AIM: To study and execute the command line arguments using $#ARGV.
PROCEDURE:
1. Open Terminal and type the program in vi editor.
2. Execute the program and note the output.
PROGRAM:
$numArgs = $#ARGV + 1;
print ‘Thanks! You gave me $numArgs command line arguments \n”;
foreach $argnum(0..$#ARGV){
print “$ARGV [$argnum] \n”;
}
OUTPUT:
RESULT: The perl program that illustrates Command line arguments was successfully
executed.
BI0313 / Perl Programming Laboratory 5
35 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 15 DATE:
STDUID/STDGID PERL SCRIPTS
AIM: To study and execute the stduid/stdgid file permissions using perl
PROCEDURE:
1. Open terminal and type the program in a text editor, save with .pl extension
2. Execute and run the chmod file permissions command to obtain the output
The long form of ls, ls –l shows the stduid/stdgid programs by listing an –s instead of –/x
When the stduid bit is turned on using the command chmod u+s stduid.pl, the privileges
of the process are set to that of the owner/user of the file
When the stdgid bit is turned on using the command chmod g+s stdgid.pl, the privileges of
the process are set to that of the group of the file
PROGRAM:
print “Welcome! This program sets file permissions \n”;
In the TERMINAL:
#ls –l
‐ rw‐r‐ ‐ r‐ ‐ stduid.pl
‐ rw‐r‐ ‐ r‐ ‐ stdgid.pl
#chmod a+x stduid.pl
#ls –l
‐rwsr‐sr‐x stduid.pl
#chmod g+x stdgid.pl
#ls –l
‐rwsr‐sr‐x stdgid.pl
BI0313 / Perl Programming Laboratory 5
36 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
RESULT: The perl program that illustrates STDUID/STDGID perl scripts was successfully
executed
BI0313 / Perl Programming Laboratory 5
37 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
EX.NO: 16 DATE:
CREATING A STATIC HTML FILE
AIM: To create and view the contents of a static html file using Perl programming.
PROCEDURE:
• Open Terminal and type the program in vi editor using vi html.pl command.
This creates a .html file in the root directory and can be viewed using a standard
browser.
• Execute to create and run to view the html page.
PROGRAM:
Use Fentl; # The Module used for operations on file handles and i/o device handles, to read,
extend attributes and control blocking etc.
print “Content type : text/html”;
sysopen (HTML, “myhtml.html”, O_RDWR/O_EXCL/O_CREAT,0755);
printf HTML “<html>\n”;
printf HTML “<head>\n”;
printf HTML “<title>My Home Page!</title>\n”;
printf HTML “</head>\n”;
printf HTML “<body>\n”;
printf HTML “<palign = ‘center’>This is an HTML page</p>”;
printf HTML “</body>\n”;
printf HTML “</html>\n”;
close (HTML);
BI0313 / Perl Programming Laboratory 5
38 th semester
SRM UNIVERSITY
DEPARTMENT OF BIOINFORMATICS
NAME : Bhupendra Khandelwal REG NO : 11207019
Html file in the root has been created.
Open: /root/myhtml.html file
OUTPUT:
RESULT: A static HTML file using perl programming was successfully created.
BI0313 / Perl Programming Laboratory 5
39 th semester