Created
October 2, 2012 17:32
-
-
Save sashaphanes/3821455 to your computer and use it in GitHub Desktop.
Open a text file and find a motif in the truncated text found inside
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
my $DNAfilename = 'exampleSequence.txt'; | |
unless (open(DNAFILE, $DNAfilename)) { | |
print "Could not open file $DNAfilename\n\n"; | |
exit; | |
} | |
my @DNA = <DNAFILE>; | |
close DNAFILE; | |
my $DNA = join('',@DNA); | |
$DNA =~ s/\s//g; | |
print "Here is the file content:\n", "$DNA\n\n"; | |
my $motif; | |
do { | |
print "Enter a motif to search for: "; | |
$motif = <STDIN>; | |
chomp $motif; | |
if ($DNA =~ /$motif/) { | |
print "I found it!\n\n"; | |
} | |
else { | |
print "I could not find it.\n\n"; | |
} | |
} until ($motif =~ /^\s*$/); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment