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

This node was taken out by the NodeReaper on Nov 30, 2010 at 13:00 UTC
  • Comment on Reaped: Keeping one colmun fixed and second column changed at different intervals to print the output

Replies are listed 'Best First'.
Re: Keeping one colmun fixed and second column changed at different intervals to print the output
by chrestomanci (Priest) on Nov 30, 2010 at 12:09 UTC

    Firstly, you appear to have double posted. The Jantors will probably remove it shortly, but in the meantime, it might be a good idea to edit the other post to just "delete me" or suchlike.

    I think you need to clarify what you are trying to achieve. Perhaps by giving an example of the output you want as well as the input. You should also tidy your code, so that it is easer to read, as the indenting makes it hard to follow.

    Your code also contains some strange features, such as where you read the whole line into the array @list, join it to the scalar $f and then split it again into another array @t. It makes no sense. Better still would be to read and process your file linewise as part of the foreach loop.

    You need to use strict and warnings. Always and everywhere.

    Another improvement would be to name the fields when your split each line instead of using array indexes, as that will make the code easier to read, and help your understanding of what you are doing. If you do that then:

    my @x = split("\t",$_);

    Becomes:

    my($index, $key, $data, @rest) = split("\t",$_);

    The if statements further down then become more readable. (Obviously you would need to choose your own variable names to match what you are doing. I just guessed some likely looking names.)

    Modifying your code with these suggestions gives us:

    #!/usr/bin/perl -w use strict; use warnings; open (FILE,"$ARGV[0]") or die; open (WRITE,">ca_0.01_1.txt"); while( my $line = <FILE> ) { my($index, $key, $data, @rest) = split("\t",$line); if(($key<=0.01) && ($index=="0")) { next if ( $data>=-8); next if ($data<-9); #next if ($index!=0); #next if ($index!=1); print WRITE ($index, $key, $data, @rest),"\n"; } } close (WRITE); close (FILE); exit;

    You still need to clarify what you are doing, because it still makes no sense.