Exercise 4.1

From Earlham CS Department
Revision as of 23:33, 20 September 2009 by Erika (talk | contribs) (New page: Return to Week 1 Exercise 4.1 in <i>Beginning Perl for Bioinformatics</i>. #!/usr/bin/perl -w use strict; #Erika Phelps #Sept 20, 2009 #Homework Chp 4 #(using example 4-2) #concate...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Return to Week 1

Exercise 4.1 in Beginning Perl for Bioinformatics.

  1. !/usr/bin/perl -w

use strict;

  1. Erika Phelps
  2. Sept 20, 2009
  3. Homework Chp 4
  1. (using example 4-2)
  2. concatemating DNA (that means, joining strings of DNA together)
  1. Store two DNA fragments into two variables called $DNA1 and $DNA2
  2. REMOVE SEMICOLON
  3. Error message: 5 lines that say "global symbol requires explicit
  4. package name. Syntex error on line 9 (correct) near "my"

my $DNA1 = 'ACGGGAGGACGGGAAAATTACTACGGATTAGC'; my $DNA2 = 'ATAGTGCCGTGAGAGTGATGTAGTA';

    • MISSPELL PRINT*
  1. Error message: String found where operator expected line 22 (correct) near
  2. "prnt" + message... (do you need to predeclare "prnt?)
  3. Syntax error ... also NA fragments
  4. 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*
  1. Error message:none, just added a curly brace in front of variable
    • TYPE RANDOM TEXT* ("hello world" in comments w/out preceding "#")
  2. Error message:First part of program ran, then message "Can't locate object
  3. method "hello" via package "world" (perhaps you forgot to load "world"?
  1. Concatemate the DNA fragments into a third variable and print them
  2. 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";

  1. An alternative way using the "dot operator":
  2. 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";

  1. 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;


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