My first reply went missing, so here it is again:

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.


In reply to Re: Keeping one colmun fixed and second column changed at different intervals to print the output by chrestomanci
in thread Keeping one colmun fixed and second column changed at different intervals to print the output by vis1982

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.