Hi Guys,
I can't use 'revcom' module of page 107. I get the msg: "Use of uninitialized value in concatenation (.) or string at test.pl line 12.
". If I put only 'print $revcom_dna' I get the msg:"Use of uninitialized value in print at test.pl line 12.
". So what is wrong?
Thank you in advance.
(01-02-2012 05:03 PM)Joporci Wrote: [ -> ]Hi Guys,
I can't use 'revcom' module of page 107. I get the msg: "Use of uninitialized value in concatenation (.) or string at test.pl line 12.
". If I put only 'print $revcom_dna' I get the msg:"Use of uninitialized value in print at test.pl line 12.
". So what is wrong?
Thank you in advance.
Hi,
Would you be able to post the code you're using? I've had a look at the code in the book and I can't see anything wrong...
Here's my test script (i've put the revcom subroutine in the main script and removed the comments but this would not have any effect on the outcome):
Code:
#! /usr/bin/env perl
use strict;
use warnings;
my $dna = 'ACTGACTGACTG';
my $revcom = revcom($dna);
print "DNA: $dna \n";
print "Reverse Compliment: $revcom \n";
sub revcom {
my ($dna) = @_;
my $revcom = reverse $dna;
$revcom =~ tr/ACGTacgt/TGCAtgca/;
return $revcom;
}
Thanks,
Daz
(01-03-2012 08:35 PM)Daz Wrote: [ -> ]Hi,
Would you be able to post the code you're using? I've had a look at the code in the book and I can't see anything wrong...
Here's my test script (i've put the revcom subroutine in the main script and removed the comments but this would not have any effect on the outcome):
Daz
Hello,
Yes it works when they are in the same script. I tried to separate the subroutine of the main script.
So here is 'MySubs.pm' module:
Code:
#!/usr/bin/perl
sub revcom {
my ($dna) = @_;
my $reccom = reverse $dna;
$revcom =~ tr/ACGTacgt/TGCAtgca/;
return $revcom;
}
sub print_array {
my ($array_ref) = @_;
foreach (@{array_ref}) {
print $_ . "\n";
}
}
1;
The script to run and reverse the DNA sequence is:
Code:
#!/usr/bin/perl
use strict;
use warnings;
use MySubs;
my $dna = 'ACTGAAA';
print "My DNA string is " . $dna . "\n";
my $revcom_dna = revcom($dna);
print $revcom_dna;
Both are in the same directory.
I tried remove the '1;' and the shebang from MySubs.pm but it didn't work (maybe it is a bit obvious).
Thank you
Joporci
Hi,
Ok, I found a few of bugs in your MySubs.pm that were or were going to cause issues, first here's the corrected code:
Code:
sub revcom {
my ($dna) = @_;
# my $reccom = reverse $dna;
my $revcom = reverse $dna;
$revcom =~ tr/ACGTacgt/TGCAtgca/;
return $revcom;
}
sub print_array {
my ($array_ref) = @_;
# foreach (@{array_ref}) {
foreach (@{$array_ref}) {
print $_ . "\n";
}
}
1;
The problems were:
- You don't need the shebang line in a module.
- You had a typo in your 'revcom' routine - the first hashed out line. You were creating a variable called $reccom rather than $revcom.
- You also had a syntax error in the 'print_array' routine - the second hashed out line. When de-referencing referenced variables you still need to call them with the $ symbol or perl thinks you're trying to run a function.
I hope this helps.
p.s. Not nagging, but I do hope that code was indented before you posted it into the forum - a simple thing like indenting code can sometimes help to find or prevent small (and often infuriating) bugs...
Hi Daz,
Yes it was my mistake. What a shame.
Now it works fine. Next time I will pay more attention before posting 'nonsense' questions in the forum.
Thank you,
Joporci
(01-04-2012 09:31 AM)Joporci Wrote: [ -> ]Now it works fine. Next time I will pay more attention before posting 'nonsense' questions in the forum.
No need to worry, we all made these mistakes when starting out with programming. And don't worry about posting simple questions on here, this is what we intended the site for.
