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;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.