not really sure what is a motif here, but this can't stop me to fail, of course XDD ... please, save the facepalms for the end, thanks ;-)
Only a draft, unworking and untested...but can give you some ideas
use 5.010;
my ($file, $motif) = @ARGV;
my $warn = <<'EOF';
Number or arguments incorrect, Please run this program
with 2 arguments, a file and a motif to count the number
of letters between any two motifs: i.e.
perl script.pl myfile mymotif
EOF
if (scalar @ARGV != 2) {print $warn}
if (scalar @ARGV == 2){
open (my $DNAFILE, '<', $file)
or die "I need that you provide a file. Cannot open file $!";
## $DNAFILE = join( '', @DNA);
## don't understand this line ... can you explain this?
$DNAFILE =~ s/\s//g; # Remove whitespace, ok
if ( $DNAFILE =~ /$motif/ ) {
print "\nI found it!\n";
# Count number of nt between two motifs
my $string ="@DNA"; # same question, explain please, why do you need t
+his?
## mmmh... are you trying to say "\@DNA"?
say "Lengths are:", $_ for map { sprintf("%d", length) } split /$
+motif/, $string;
# Count number of motifs
my $count=($string =~ m/$motif/g);
print "Number of motifs: $count.\n\n";
close DNAFILE;
} else { print "The motif: $motif was not found in the file $file.\n"}
} # first else block
__END__
Your turn
(Updated: problem with $warn fixed)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.