morio56 has asked for the wisdom of the Perl Monks concerning the following question:
The file am reading in looks like this: <@chr1 nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn @chr2 nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn> My problem is this will only output the last iteration i.e @chr2 followed by the nnnn's. How can I make it return the file the way it looks like from the input i.e. @chr1 nnnn.. followed by @chr2 nnn....? thanks.print "Please enter the cns file:\n"; chomp($t=<STDIN>); open(THE,$t) or die "Can not open file: $!\n"; @data=<THE>; close THE; $sequence=''; $end=0; foreach $line(@data){ if($line=~/^\@/){ $chro=$line; }elsif($line=~/^[a-zA-Z]/){ $sequence.=$line; }else{ $end++ } } $sequence=~s/\s*$//g; print $chro,"\n"; print $sequence,"\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: foreach loop
by wind (Priest) on May 04, 2011 at 16:23 UTC | |
by morio56 (Initiate) on May 04, 2011 at 16:26 UTC | |
by moritz (Cardinal) on May 04, 2011 at 16:33 UTC | |
|
Re: foreach loop
by ikegami (Patriarch) on May 04, 2011 at 16:56 UTC | |
by morio56 (Initiate) on May 04, 2011 at 17:17 UTC | |
by Gulliver (Monk) on May 04, 2011 at 17:58 UTC | |
by morio56 (Initiate) on May 04, 2011 at 19:27 UTC | |
by ww (Archbishop) on May 04, 2011 at 21:00 UTC |