in reply to Iterating single line within a For Loop
then my $seq = <INFILE>; will grab the line after a line starting with @ because the while test is run once per iteration. A for loop constructs the entire list first, which means it pulls in all lines before the first iteration.while (<INFILE>) { if (/^@(\S+)/) { print "$1\n"; my $seq = <INFILE>; } }
Also note that, while you are fine here, an unescaped @ in a regular expression will usually end up looking like an array in Perl; it's probably a good idea to get in the habit of escaping them.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Iterating single line within a For Loop
by diyaz (Beadle) on Feb 25, 2015 at 19:20 UTC |