Difference between revisions of "Exercise 4.1"
Line 4: | Line 4: | ||
<nowiki>#!/usr/bin/perl -w | <nowiki>#!/usr/bin/perl -w | ||
− | use strict; | + | use strict;</nowiki> |
− | #Erika Phelps | + | <nowiki>#Erika Phelps |
#Sept 20, 2009 | #Sept 20, 2009 | ||
− | #Homework Chp 4 | + | #Homework Chp 4</nowiki> |
− | #(using example 4-2) | + | <nowiki>#(using example 4-2) |
− | #concatemating DNA (that means, joining strings of DNA together) | + | #concatemating DNA (that means, joining strings of DNA together)</nowiki> |
− | #Store two DNA fragments into two variables called $DNA1 and $DNA2 | + | <nowiki>#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'; | + | my $DNA2 = 'ATAGTGCCGTGAGAGTGATGTAGTA';</nowiki> |
− | #*MISSPELL PRINT* | + | <nowiki>#*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"; | + | print "Here are the orginal two DNA fragments: \n\n";</nowiki> |
print $DNA1, "\n"; | print $DNA1, "\n"; | ||
Line 32: | Line 32: | ||
print $DNA2, "\n\n"; | print $DNA2, "\n\n"; | ||
− | #*ADD A CURLY BRACE RANDOMLY* | + | <nowiki>#*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 "#") | ||
#Error message:First part of program ran, then message "Can't locate object | #Error message:First part of program ran, then message "Can't locate object | ||
− | #method "hello" via package "world" (perhaps you forgot to load "world"? | + | #method "hello" via package "world" (perhaps you forgot to load "world"?</nowiki> |
− | + | <nowiki> | |
#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"; | + | my $DNA3 = "$DNA1$DNA2";</nowiki> |
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; | + | my $DNA4 = $DNA1 . $DNA2;</nowiki> |
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: | ||
− | #Sometimes a simple error generates many lines of code. When checking for errors | + | <nowiki>#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...</nowiki> |
Revision as of 22:37, 20 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"? #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...