You start to loop through the array @motiffile, but as you get through to the end of this snippet, you return from the sub with one result, thus leaving the loop.foreach $motiffile(@motiffile){ if($motiffile =~ /(^[A|S]\d+\s+|^[A|S]\d+b\s+)([A-Z]+)(\s+.*)$ +/){ my $name = $1; my $site = $2; $regexp = IUB_to_regexp($site); $motif_hash{$name} = "$site $regexp\n"; print "motif : $site\n"; print "The regexp : $regexp\n"; } } return $regexp; ...
What you can do is collect all results, for example by using this instead of the return statement:
(and of course, @regexp must be declared higher up in the sub), and after the loop block, return a combined regexp:push @regexp, $regexp
return join '|', @regexp;
update Oops, I misread the code (bad indentation), you return after the loop block, instead of in it... But the end result is nearly the same, except now you return the last $regexp instead of the first.
Put my push statement in the loop block.
In reply to Re: codes error
by bart
in thread codes error :(
by Bio_student
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |