Difference between revisions of "Exercise 4.1"

From Earlham CS Department
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
Return to [[Week 1]]
 
Return to [[Week 1]]
  
Exercise 4.1 in <i>Beginning Perl for Bioinformatics</i>.
+
'''Exercise 4.1 in <i>Beginning Perl for Bioinformatics</i>.'''
  
<nowiki>#!/usr/bin/perl -w
+
<pre>#!/usr/bin/perl -w
use strict;</nowiki>
+
use strict;
  
<nowiki>#Erika Phelps
+
#Erika Phelps
 
#Sept 20, 2009
 
#Sept 20, 2009
#Homework Chp 4</nowiki>
+
#Homework Chp 4
  
<nowiki>#(using example 4-2)
+
#(using example 4-2)
#concatemating DNA (that means, joining strings of DNA together)</nowiki>
+
#concatemating DNA (that means, joining strings of DNA together)
  
<nowiki>#Store two DNA fragments into two variables called $DNA1 and $DNA2
+
#Store two DNA fragments into two variables called $DNA1 and $DNA2
 
#
 
#
 
#REMOVE SEMICOLON
 
#REMOVE SEMICOLON
Line 19: Line 19:
 
#package name. Syntex error on line 9 (correct) near "my"
 
#package name. Syntex error on line 9 (correct) near "my"
 
my $DNA1 = 'ACGGGAGGACGGGAAAATTACTACGGATTAGC';
 
my $DNA1 = 'ACGGGAGGACGGGAAAATTACTACGGATTAGC';
my $DNA2 = 'ATAGTGCCGTGAGAGTGATGTAGTA';</nowiki>
+
my $DNA2 = 'ATAGTGCCGTGAGAGTGATGTAGTA';
  
<nowiki>#*MISSPELL PRINT*
+
#*MISSPELL PRINT*
 
#Error message: String found where operator expected line 22 (correct) near
 
#Error message: String found where operator expected line 22 (correct) near
 
#"prnt" + message... (do you need to predeclare "prnt?)
 
#"prnt" + message... (do you need to predeclare "prnt?)
 
#Syntax error ... also NA fragments
 
#Syntax error ... also NA fragments
 
#Print the DNA onto the screen
 
#Print the DNA onto the screen
print "Here are the orginal two DNA fragments: \n\n";</nowiki>
+
print "Here are the orginal two DNA fragments: \n\n";
  
 
print $DNA1, "\n";
 
print $DNA1, "\n";
Line 32: Line 32:
 
print $DNA2, "\n\n";
 
print $DNA2, "\n\n";
  
<nowiki>#*ADD A CURLY BRACE RANDOMLY*
+
#*ADD A CURLY BRACE RANDOMLY*
 
#Error message:none, just added a curly brace in front of variable
 
#Error message:none, just added a curly brace in front of variable
 
#*TYPE RANDOM TEXT* ("hello world" in comments w/out preceding "#")
 
#*TYPE RANDOM TEXT* ("hello world" in comments w/out preceding "#")
Line 40: Line 40:
 
#Concatemate the DNA fragments into a third variable and print them
 
#Concatemate the DNA fragments into a third variable and print them
 
#Using "string interpolation"
 
#Using "string interpolation"
my $DNA3 = "$DNA1$DNA2";</nowiki>
+
my $DNA3 = "$DNA1$DNA2";
  
 
print "Here is the concatenation of the first two fragments (version 1):\n\n";
 
print "Here is the concatenation of the first two fragments (version 1):\n\n";
  
 
print "$DNA3\n\n";
 
print "$DNA3\n\n";
<nowiki>
+
 
 
#An alternative way using the "dot operator":
 
#An alternative way using the "dot operator":
 
#Concatenate the DNA fragments into a third variable and print them
 
#Concatenate the DNA fragments into a third variable and print them
my $DNA4 = $DNA1 . $DNA2;</nowiki>
+
my $DNA4 = $DNA1 . $DNA2;
  
 
print "Here is the concatentation of the first two fragments (version 2):\n\n";
 
print "Here is the concatentation of the first two fragments (version 2):\n\n";
Line 63: Line 63:
  
  
<nowiki>#Sometimes a simple error generates many lines of code. When checking for errors
+
#Sometimes a simple error generates many lines of code. When checking for errors
 
#should try things out one at a time until no error message remains instead
 
#should try things out one at a time until no error message remains instead
 
#of trying to fix everything at once!  
 
#of trying to fix everything at once!  
 
#Yes, the errors do seem to very accurately locate the source of the error and
 
#Yes, the errors do seem to very accurately locate the source of the error and
#which line! I like the suggestion feature for what may have gone wrong...</nowiki>
+
#which line! I like the suggestion feature for what may have gone wrong...</pre>

Latest revision as of 11:00, 23 September 2009

Return to Week 1

Exercise 4.1 in Beginning Perl for Bioinformatics.

#!/usr/bin/perl -w
use strict;

#Erika Phelps
#Sept 20, 2009
#Homework Chp 4

#(using example 4-2)
#concatemating DNA (that means, joining strings of DNA together)

#Store two DNA fragments into two variables called $DNA1 and $DNA2
#
#REMOVE SEMICOLON
#Error message: 5 lines that say "global symbol requires explicit
#package name. Syntex error on line 9 (correct) near "my"
my $DNA1 = 'ACGGGAGGACGGGAAAATTACTACGGATTAGC';
my $DNA2 = 'ATAGTGCCGTGAGAGTGATGTAGTA';

#*MISSPELL PRINT*
#Error message: String found where operator expected line 22 (correct) near
#"prnt" + message... (do you need to predeclare "prnt?)
#Syntax error ... also NA fragments
#Print the DNA onto the screen
print "Here are the orginal two DNA fragments: \n\n";

print $DNA1, "\n";

print $DNA2, "\n\n";

#*ADD A CURLY BRACE RANDOMLY*
#Error message:none, just added a curly brace in front of variable
#*TYPE RANDOM TEXT* ("hello world" in comments w/out preceding "#")
#Error message:First part of program ran, then message "Can't locate object
#method "hello" via package "world" (perhaps you forgot to load "world"?</nowiki>
<nowiki>
#Concatemate the DNA fragments into a third variable and print them
#Using "string interpolation"
my $DNA3 = "$DNA1$DNA2";

print "Here is the concatenation of the first two fragments (version 1):\n\n";

print "$DNA3\n\n";

#An alternative way using the "dot operator":
#Concatenate the DNA fragments into a third variable and print them
my $DNA4 = $DNA1 . $DNA2;

print "Here is the concatentation of the first two fragments (version 2):\n\n";

print "$DNA4\n\n";

#Print the same thing without using the variable $DNA3 or $DNA4

print "Here is the concatentation of the first two fragments (version 3):\n\n";

print $DNA1, $DNA2, "\n";

exit;


#Sometimes a simple error generates many lines of code. When checking for errors
#should try things out one at a time until no error message remains instead
#of trying to fix everything at once! 
#Yes, the errors do seem to very accurately locate the source of the error and
#which line! I like the suggestion feature for what may have gone wrong...