http://www.perlmonks.org?node_id=161961

lolly has asked for the wisdom of the Perl Monks concerning the following question:

Hi, i am stuck. i have a file which contains various stretches of DNA in fasta format e.g
>12343 ACTAGCTAGCTGATGTCGTCCTACACAT >4567465 ACTAGCGGCGTGCCTAGTACGTACTTCTTG
in which each record is separated by a newline. I am trying to write code that will return all sequences containing more than 250 bases. But i think i am getting confused with nested loops etc because although my program runs fine it still returns everything. can anyone help?? this is my code:
#! /usr/local/bin/perl -w use strict; open (INPUT, $ARGV[0]) or die "unable to open file"; my $sequence; my $count =0; my $base = ("A"|"C"|"G"|"T"); my @array; my $ideal = 250; while (<INPUT>) { $sequence = $_; @array = (); @array = split (/\n/, $sequence); foreach $base ($sequence) { $count++; if ($count > $ideal) { print "$base\n"; } } }
i am new to perl and would appreciate any help. lolly