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.


In reply to Re: Special Variable help by AnomalousMonk
in thread Special Variable help by utterlyconfused

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.