Below is the code I have for searching a FASTA file entered at the command line for a user-provided motif. When I run it and enter a motif that I know is in the file it returns 'Motif not found'. I'm only a beginner in Perl, and I can't fugure out how to get it to print motif found, let alone return the title line. I would appreciate any help in resolving this.
Thanks.
use warnings;
use strict;
my $motif;
my $filename;
my @seq;
#my $motif_found;
my $scalar;
$filename = $ARGV[0];
open (DNAFILE,$filename) || die "Cannot open file\n";
@seq = split(/[>]/, $filename);
print "Enter a motif to search for; ";
$motif = <STDIN>;
chomp $motif;
foreach $scalar(@seq) {
if ($scalar =~ m/$motif/ig) {
print "Motif found in following sequences\n";
print $scalar;
} else {
print "Motif was not found\n";
}
}
close DNAFILE;