Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Module
01-02-2012, 05:03 PM
Post: #1
Module
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.
Find all posts by this user
Quote this message in a reply
01-03-2012, 08:35 PM (This post was last modified: 01-04-2012 09:09 AM by Daz.)
Post: #2
RE: Module
(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
Visit this user's website Find all posts by this user
Quote this message in a reply
01-03-2012, 11:06 PM (This post was last modified: 01-04-2012 08:37 AM by Daz.)
Post: #3
RE: Module
(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
Find all posts by this user
Quote this message in a reply
01-04-2012, 08:51 AM (This post was last modified: 01-04-2012 08:52 AM by Daz.)
Post: #4
RE: Module
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:

  1. You don't need the shebang line in a module.
  2. You had a typo in your 'revcom' routine - the first hashed out line. You were creating a variable called $reccom rather than $revcom.
  3. 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. Smile

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...
Visit this user's website Find all posts by this user
Quote this message in a reply
01-04-2012, 09:31 AM
Post: #5
RE: Module
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
Find all posts by this user
Quote this message in a reply
01-04-2012, 09:35 AM
Post: #6
RE: Module
(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. Smile
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)