Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I too am uncertain about your objective, but from what I see I suspect your solution is more complicated than it needs to be. The following is much simpler, and might be what you want. If not, it might be a basis for modification to get what you want. To that end, I suggest starting with something simple that works, and then making one change at a time to make it closer to what you want, making sure your program runs as expected at each step.

Anyway, here is something you might consider:

use strict; use warnings; use Data::Dumper; my $minimum_difference = 10; my $input_filename = 'e_d.txt'; open(my $input_fh, '<', $input_filename) or die "$input_filename: $!"; my $previous_fields; while (my $line = <$input_fh>) { chomp($line); my $fields = [ split(/\t/, $line) ]; if( defined($previous_fields) and $previous_fields->[0] eq $fields->[0] and $previous_fields->[1] ne $fields->[1] and $previous_fields->[-2] - $fields->[-2] < $minimum_difference ) { print "Failed test:\n" . Dumper([ $previous_fields, $fields ]) + . "\n\n"; } $previous_fields = $fields; }

I have made many assumptions. Most significant is the assumption that you are only interested in differences between consecutive lines in the input file.

I have used Data::Dumper to dump both arrays of fields when the test fails. This module is very helpful when you are developing code that deals with data structures. You also might want to read perldsc.

In reply to Re: Accessing 2D array values and comparing by ig
in thread Accessing 2D array values and comparing by mSe

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (4)
    As of 2018-10-22 01:26 GMT
    Find Nodes?
      Voting Booth?
      When I need money for a bigger acquisition, I usually ...

      Results (119 votes). Check out past polls.