in reply to Special Variable help
The
while (<FH>) { ... }
construct reads by default to the special scalar variable $_ (dollar-underscore; see perlvar), but you are matching against the variable $line, which is never defined.
Use of strictures and warnings is very wise, but not in the 'shebang' line, where they are ineffective: use them separately in the body of the script.
Try something like the following (untested (Update: changed some variable names to be self-documenting)):
#!usr/bin/perl use warnings; use strict; my $filename = $ARGV[0] or die "no file name given"; open my $fh, '<', $filename or die "opening '$filename': $!"; my $previous_line = ''; while (defined(my $current_line = <$fh>)) { chomp $current_line; if ($current_line =~ m{ \A [ACGTacgt]+ \z }xms) { print "$previous_line\n"; print "$current_line\n"; } $previous_line = $current_line; } close $fh or die "closing '$filename': $!";
This will print every line that contains only base-pair letters, along with the line before it in the file. When this works, modify the
m{ \A [ACGTacgt]+ \z }xms
regex to match whatever a 'motif' is.
Update: Since it looks like you're working with a FASTA-formatted file, check out the FASTA-related modules in CPAN; I'm not a bio-guy, so I can't advise which might be best for you.
|
|---|