Exercise 4.1: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (2 intermediate revisions 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>.''' | ||
< | <pre>#!/usr/bin/perl -w | ||
use strict; | use strict; | ||
| Line 36: | Line 36: | ||
#*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" | ||
| Line 67: | Line 67: | ||
#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...</ | #which line! I like the suggestion feature for what may have gone wrong...</pre> | ||
Latest revision as of 16: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...