Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

subroutine redefined 2

Status
Not open for further replies.

ailse

Programmer
Jan 20, 2004
79
GB
Hi all - I am having a pretty frustrating time with the following small perl program - every time i try to run it, I get the same error: "subroutine match_positions redefined at line 73"

Code:
#!/usr/bin/perl
# Make restriction map from user queries on names of restriction enzymes

use strict;
use warnings;
use dna;    

open(INFILE,"c:/perl/source/program/outfile.txt");

# Declare and initialize variables
my %rebase_hash = (  );
my @file_data = (  );
my $query = '';
my $dna = <INFILE>;
my $recognition_site = '';
my $regexp = '';
my @locations = (  );


# Get the REBASE data into a hash, from file &quot;bionet&quot;
%rebase_hash = parseREBASE('bionet');

# Prompt user for restriction enzyme names, create restriction map
do {
    print &quot;Search for what restriction site for (or quit)?: &quot;;
    
    $query = <STDIN>;

    chomp $query;

    # Exit if empty query
    if ($query =~ /^\s*$/ ) {

        exit;
    }

    # Perform the search in the DNA sequence
    if ( exists $rebase_hash{$query} ) {

        ($recognition_site, $regexp) = split ( &quot; &quot;, $rebase_hash{$query});

        # Create the restriction map
        @locations = match_positions($regexp, $dna);

        # Report the restriction map to the user
        if (@locations) {
            print &quot;Searching for $query $recognition_site $regexp\n&quot;;
            print &quot;A restriction site for $query at locations:\n&quot;;
            print join(&quot; &quot;, @locations), &quot;\n&quot;;
        } else {
            print &quot;A restriction site for $query is not in the DNA:\n&quot;;
        }
    }
    print &quot;\n&quot;;
} until ( $query =~ /quit/ );

exit;

################################################################################
#
# Subroutine
#
# Find locations of a match of a regular expression in a string
#
# 
# return an array of positions where the regular expression
#  appears in the string
#

sub match_positions {

    my($regexp, $sequence) = @_;

    use strict;

   
    #
    # Declare variables
    #

    my @positions = (  );

    #
    # Determine positions of regular expression matches
    #
    
    while ( $sequence =~ /$regexp/ig ) {

        push ( @positions, pos($sequence) - length($&) + 1);
    }

    return @positions;
}


any ideas why i keep getting this error?

thanks in advance :)
 
Do you have a match_positions sub in the dna module you're using?
 
That message is suggesting that the match_positions subroutine is being defined twice, though I don't see it in that code. What is 'dna' that you're importing? Is it possible that there's a sub called match_positions defined in that too?

Either way, if I were you, I'd change the name of your match_positions if it's not easy to find wherever else it's defined.

HTH
 
thanks both of you, that was exactly the problem! I was trying to keep all my subroutines separate in a different module, but i guess that one slipped through the net :)
 
I don't think it has any bearing on the problem you mentioned, but I notice you've got a 'use strict' inside sub 'match_positions', in addition to the one at the top of the file. Is there a reason for the second 'use strict'? Seems unnecessary, as the scope of the first one includes the subroutine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top