It looks it will work, but only insofar you have only one long line in your file. If your file comes with more than one line, you're in trouble. I would use a loop or some other mechanism to make sure it will still work fine the day I get two or more lines. Below, I
localized
$/ (the input record separator) so that the whole file will be slurped into the scalar.
As a side note, there are some commonly agreed best practices in the Perl community. Among them:
- use the use warnings; pragma rather than the -w flag
- Use lexical filehandles rather than bareword filehandles
- Use the three-argument syntax for the open function
Putting all this together, this a possible (untested) rewrite of your script:
#!/usr/bin/perl
use strict;
use warnings;
my $infile = shift;
open my $INPUT_FILE, "<", $infile" or die "can't open $infile: $!";
local $/; # the whole file will be slurped, even if it has several lin
+es
my $dna = <$INPUT_FILE>;
if ( $dna =~ m/[^actg\s]/i ) {
print "File contains something besides actg sequence.\n";
} else {
print "good!\n";
}
close $INPUT_FILE;