Difference between revisions of "Basic Perl Grammar"

From Biolecture.org
imported>Seung-hoon Kim
imported>Seung-hoon Kim
 
(One intermediate revision by the same user not shown)
Line 36: Line 36:
  
 
<p>exit;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;: Instruction for end of the program</p>
 
<p>exit;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;: Instruction for end of the program</p>
 +
 +
<p>* Another way to read whole&nbsp;lines in a file&nbsp; - use array variable (@)</p>
 +
 +
<p>Ex) @DNASeq = &lt;DNAFILE&gt;;&nbsp;&nbsp;&nbsp;&nbsp; : Array variable&nbsp;consists of n components.</p>
 +
 +
<p>First line will be stored in a first component and second line will be stored in a second component and so on.</p>
 +
 +
<p>&nbsp;</p>
 +
 +
<p>use strict;&nbsp;&nbsp;&nbsp;&nbsp; : to check typing errors</p>
 +
 +
<p>use warnings;&nbsp;&nbsp; :&nbsp; to make easy debugging ( find and modify errors )</p>
 +
 +
<p>&nbsp;</p>
 +
 +
<p>subroutine&nbsp;: to make a module and utilize it in main program (we can use it anytime)</p>
 +
 +
<p>&nbsp; basic structure of subroutine :</p>
 +
 +
<p>sub subroutine name {</p>
 +
 +
<p>execute statement</p>
 +
 +
<p>}</p>
  
 
<p>&nbsp;</p>
 
<p>&nbsp;</p>

Latest revision as of 11:06, 16 June 2016

# : program statement to improve understanding of the program. It is ignored when you run the program

-w : It enables to print out error message when you make an error.

print : It prints out the following character string, number to your monitor

\n : new line character. It designates the end of a line of text and the start of a new line

Variable : The place to store data

 1. $ : Scalar, to store specific number or character string

 2. @ : Array, to store several values in sequence

 3. % : Associative array, dataset without sequence

= : Assignment operator to give a value to the variable

To open a file using perl program

<STDIN> : The link between perl program and file. We can get the values from a file using this standard input device

Ex) $DNAfilename = <STDIN>;

chomp $DNAfilename;   : To remove the last new line character when you input your filename

open(DNAFILE, $DNAfilename);    : to open a file, we have to make a link between perl program and the file using open function

$DNASeq = <DNAFILE>;     : to read the open file - we can only read one line using scalar variable

while : to read the whole lines in a file

Ex) while( $DNASeq = <DNAFILE> )

close DNAFILE;     : to close the open file

exit;       : Instruction for end of the program

* Another way to read whole lines in a file  - use array variable (@)

Ex) @DNASeq = <DNAFILE>;     : Array variable consists of n components.

First line will be stored in a first component and second line will be stored in a second component and so on.

 

use strict;     : to check typing errors

use warnings;   :  to make easy debugging ( find and modify errors )

 

subroutine : to make a module and utilize it in main program (we can use it anytime)

  basic structure of subroutine :

sub subroutine name {

execute statement

}

 

 

 

KSH_0608 Bioinformatics with Bioperl