Greetings Monks, I have a short perl script that is not behaving as it should. This is what it needs to do: 1.read a file in one line at a time 2.subtract the value in position[0] from a a starting value I call $seed 3.if the difference is >= 0.1, then print position[0]."\n" and then set $seed equal to the value in position[0] and go on to the next line 4.if the difference is <0.01, go to the next line. Here is the script that I have tried:
#!/usr/bin/perl open TAB, "test.txt"; <TAB>; $seed = 1.04; while (<TAB>){ @tab = split ' '; $diff = "$tab[0]" - "$seed"; if ($diff ge 0.1){print "@tab\n" && $seed eq $tab[0]} else {next}; }
Can anyone fix this script? Thanks much, Etbr77

In reply to Simple iteration problem by Etbr77

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.