On Fri, Sep 30, 2011 at 09:37, Nathalie Conte <n...@sanger.ac.uk> wrote:
> thanks for any clues

It's a simple one, really.. 8^)

> #!/software/bin/perl
> use warnings;
> use strict;
> open(IN, "<example.txt") or die( $! );
> open(OUT, ">>removed.txt") or die( $! );

ObCorrectness: you should say something more like

open( my $IN , '<' , 'example.txt' ) or die( $! );
open( my $OUT , '>>' , removed.txt' ) or die( $! );

and then change the filehandles correspondingly -- but that's not your problem.

> my @bad_chromosome=(6,8,14,16,18,Y);
> while(<IN>){
>   chomp;
>   my @column=split /\t/;
>       foreach my $chr_no(@bad_chromosome){
>           if ($column[0]==$chr_no){
>           next;

here's your problem -- next always applies to the innermost loop -- so
you're jumping to the next $chr_no, not the next $_.

you solve this with a loop label:

LINE: while( <IN> ) {
  chomp;
  my @column = split /\t/;
  foreach my $chr_no ( @bad_chromosome ) {
    if( $column[0] == $chr_no ) {
      next LINE;

and then the rest is all the same.

You _may_ want to switch that comparison to 'eq' instead of '==' --
didn't you have 'Y' as one of the chromosomes to drop?

>           print OUT
> $column[0],"\t",$column[1],"\t",$column[2],"/",$column[3],"\t",$column[4],"\t",$column[5],"\t",$column[6],"\t",$column[7],"\t",$column[8],"\t",$column[9],"\t",$column[10],"\t",$column[11],"\t",$column[12],"\t",$column[13],"\t",$column[14],"\n";

Oh, and this? Try something like

print (join '\t' , @column), "\n"


chrs,
john.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to