The If-statement is a method to direct the flow of operations in a program in two directions, depending on a condition. Two alternatives are given and the program has to choose one of them.
$a = 5;In the examples above either a numerical value is tested or a string is compared. In both cases the logical expression can be either true or false. If it is true then the first block is executed, if it is false the second block is executed. The second block can be omitted:
$a = 5;Then the program either executes the first block if the logical expression proves true or continues with the next program statement after the block. The block is then completely skipped and not executed.
String variables can be appended. The operator for this is the dot (.).
$no = "16";This will result in the string $date equal to "FridayMarch162007". More readable is a version where small blanks are inserted in the string:
$date = $day . " " . $month . " " . $no . " " . $year;This results in the string: "Friday March 16 2007"
Using the build-in function substr you are able to cut partial strings from a longer string, for instance you can cut characters out of a word, words from a sentence, oligomers from sequence etc.. The basic syntax is: $partial_string = substr( $some_string, $offset, $length ); The $partial_string is cut from $some_string, beginning after $offset. The length of $partial_string is $length.
The build-in function length returns the number of characters in the string. $no_of_a++; is a shorthand version of $no_of_a = $no_of_a + 1; Build-in functions exists for numerous tasks. You can find lists of functions in every PERL textbook and at the webpage www.cpan.org. Or you may look at the list of functions used in this course.
Try to count all four bases in a sequence: $no_of_a, $no_of_c, $no_of_g and $no_of_t.
Try to count dimers and trimers using substr( $seq, $position, 2) and substr( $seq, $position, 3 ).