I need to compare data and delete the ones that are redundant. Each data is made up of three lines. I am only interested to compare the numerical parts of the data. In this example there are four data, each consisting of three lines (hope this makes sense):
A 83 GLU A 90 GLU^? A 163 ARG A 83 ARG^? A 222 ARG A 5 ARG^? A 229 ALA A 115 ALA~? A 257 ALA A 118 ALA~? A 328 ASP A 95 ASP~? A 83 GLU A 90 GLU^? A 163 ARG A 83 ARG^? A 222 ARG A 5 ARG^? A 83 GLU B 90 GLU^? A 163 ARG B 83 ARG^? A 222 ARG B 5 ARG^?
I've written a code (a stupid one) for this and it worked, but my code only compares data that are positioned one after the other.
My code:
#!/usr/bin/perl open (FILE, 'bodo.txt'); open (OUTFILE, '>output.txt') or die "die"; $/ = " "; $i=0; $j=0; $k=0; $l=0; $m=0; $n=0; while ($line = <FILE>) { chomp; ($i_new, $j_new, $k_new) = (split /\s+/,$line) [ -2,-8,-14 ] ; #assign + each number to a variable ($l_new, $m_new, $n_new) = (split /\s+/,$line) [ -5,-11,-17 ] ; # assi +gn each number to a variable if ($i==$i_new && $j==$j_new && $k==$k_new && $l==$l_new && $m==$m_new + && $n==$n_new){ #do nothing } else { print OUTFILE $line; } $i=$i_new; $j=$j_new; $k=$k_new; $l=$l_new; $m=$m_new; $n=$n_new; } close (FILE); close (OUTFILE); exit;

The reason this was written was because I hadn't thought that the data to be compared could be positioned far from each other.

I am very new to Perl, and actually new to programming in general. Hope someone can help. Thank you.

In reply to delete redundant data by nurulnad

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.