Skip to content

Instantly share code, notes, and snippets.

@sashaphanes
Created October 2, 2012 17:32
Show Gist options
  • Save sashaphanes/3821455 to your computer and use it in GitHub Desktop.
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
#!/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