Exercise 4.1
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...