Difference between revisions of "Basic Perl Grammar"

From Biolecture.org
imported>Seung-hoon Kim
imported>Seung-hoon Kim
Line 6: Line 6:
  
 
<p>\n : new line character. It designates the end of a line of text and the start of a new line</p>
 
<p>\n : new line character. It designates the end of a line of text and the start of a new line</p>
 
<p>exit : Instruction for end of the program</p>
 
  
 
<p>Variable : The place to store data</p>
 
<p>Variable : The place to store data</p>
Line 18: Line 16:
  
 
<p>= : Assignment operator to give a value to the variable</p>
 
<p>= : Assignment operator to give a value to the variable</p>
 +
 +
<h3>To open a file using perl program</h3>
 +
 +
<p>&lt;STDIN&gt; : The link between perl program and file. We can get the values from a file using this standard input device</p>
 +
 +
<p>Ex) $DNAfilename = &lt;STDIN&gt;;</p>
 +
 +
<p>chomp $DNAfilename;&nbsp;&nbsp;&nbsp;: To remove the last&nbsp;new line character when you input your filename</p>
 +
 +
<p>open(DNAFILE, $DNAfilename);&nbsp;&nbsp; &nbsp;: to&nbsp;open a file, we have to&nbsp;make a link between perl program and the file using open function</p>
 +
 +
<p>$DNASeq = &lt;DNAFILE&gt;;&nbsp;&nbsp;&nbsp;&nbsp; :&nbsp;to read the open file - we can only read one line using scalar variable</p>
 +
 +
<p>while : to read the whole lines in a file</p>
 +
 +
<p>Ex) while( $DNASeq = &lt;DNAFILE&gt; )</p>
 +
 +
<p>close DNAFILE;&nbsp;&nbsp;&nbsp;&nbsp; : to close the open file</p>
 +
 +
<p>exit;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;: Instruction for end of the program</p>
 +
 +
<p>&nbsp;</p>
 +
 +
<p>&nbsp;</p>
  
 
<p>&nbsp;</p>
 
<p>&nbsp;</p>
  
 
<p><a href="http://biolecture.org/index.php/KSH_0608_Bioinformatics_with_Bioperl" title="KSH 0608 Bioinformatics with Bioperl">KSH_0608 Bioinformatics with Bioperl</a></p>
 
<p><a href="http://biolecture.org/index.php/KSH_0608_Bioinformatics_with_Bioperl" title="KSH 0608 Bioinformatics with Bioperl">KSH_0608 Bioinformatics with Bioperl</a></p>

Revision as of 21:29, 14 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

 

 

 

KSH_0608 Bioinformatics with Bioperl