I used Perl for the first time

Im taking Bioinformatics class and I keep getting Undefined & main :: Print subroutine which is called on line ReverseComp.txt 4. "error

# ReverseComp.txt => takes DNA sequence from user
# and returns the reverse complement

print ("please input DNA sequence:\n");
$DNA =<STDIN>;

$DNA =~tr/ATGC/TACG/;   # Find complement of DNA sequence

$DNA =~reverse ($DNA);  # Reverse DNA sequence

print ("Reverse complement of sequence is:\n");

print $DNA."\n";

      

This is my code and I've tried several different things on line 4 but no results. Any suggestions? (I am writing this from the tip, everything looks correct ....)

+3


source to share


1 answer


I have some notes related to your code:

  • Name your scripts with extension .pl

    instead of .txt

    . This is a common extension for Perl scripts (and .pm

    for Perl modules, reusable libraries)

  • Always start your scripts with use strict; use warnings;

    . These suggestions help you avoid common mistakes.

  • Declare your variables before using them (see my function )

  • chomp

    your input from STDIN

    to remove the newline at the end.

  • The callback function is odd. I think I $DNA =~ reverse ($DNA);

    should be$DNA = reverse ($DNA);

  • The inverse function is more commonly used with Perl arrays; with a string, you will get the reverse version of that string as I expected you to.

  • The print function can display a list of parameters, so you can print multiple things in one sentence

  • You can omit parentheses in many places, for example. reverse($a)

    matches reverse $a

    . Both are valid, but the latter is more suited to the Perl style of writing code. Perl style guide is recommended to read

In relation to your question, I think your script is correct because the print function exists in Perl and the error you received says Print (with uppercase letters, which is important in Perl). Perhaps you will run another script that you posted here.



This is your script with previous considerations ( ReverseComp.pl

):

use strict;
use warnings;

print "please input DNA sequence:\n";
chomp( my $DNA = <STDIN> );

$DNA =~ tr/ATGC/TACG/;    # Find complement of DNA sequence
$DNA = reverse $DNA;      # Reverse DNA sequence

print "Reverse complement of sequence is:\n", $DNA, "\n";

      

Either way, welcome to the fantasy world of Pearl and get ready to enjoy the ride.

+7


source







All Articles