Can someone help me with this Perl code? When I run it, nothing happens. No errors or anything which is weird to me. It reads in and opens the file just fine. I believe the problem is in the while loop or the foreach loop cause I honestly don't think I understand them. I'm very new at this with a pretty shit teacher.
Instructions: Declare a scalar variable called motif and make it AAA. Declare an array variable called locations, which is where the locations of the motif will be stored. Place the gene in a scalar variable. Now search for that motif in the amborella gene. The code should print the position of the motif and the motif found. You will need to write a while loop that searches for the motif and includes push, pos, and –length commands in order to save and report locations. Then you will need a foreach loop to print the locations and the motif. (If it only reports locations in the first line of the gene, remember that is because the gene is in a scalar variable that will only read the first line. That is acceptable.
My code so far:
#!/usr/bin/perl
use warnings;
use strict;
#Declare a scalar variable called motif and make it AAA.
my$motif="AAA";
#Declare an array variable called locations, which is where the
#locations of the motif will be stored.
my@locations=();
my$foundMotif="";
my$position=();
#Place the gene in a scalar variable.
my$geneFileName = 'amborella.txt';
open(GENEFILE, $geneFileName) or die "Can't read file!";
my$gene = <GENEFILE>;
#Now search for that motif in the amborella gene.
#The code should print the position of the motif and the motif
#found. You will need to write a while loop that searches for the
#motif and includes push, pos, and –length commands in order to
#save and report locations.
while($foundMotif =~ m/AAA/g) {
$position=(pos($foundMotif)-3);
push (@locations, $position);
}
#Then you will need a foreach loop to print the locations and the motif.
foreach $position (@locations){
print "\n Found motif: ", $motif, "\n at position: ", $position;
}
#close the file
close GENEFILE;
exit;