++Moritz and Anonymonk and toolic for encouraging good programming. I learned the hard way to always use strict; use warnings;. This will help Perl help you catch your own errors.

update: toolic and Eimi Metamorphoumai have pointed out that much of my concern about @tab was for nought.

<blockignore quality="sheepish">
I think there's one more thing to comment on in your code. The value of @tab is the number of elements in the array. I personally think that toolic's output is more helpful and is certainly more instructive, but if you really wanted the number of elements in the array, you'd have gotten:

1 3 2
for toolic's results, since that's the number of elements in the arrays on the lines that satisfy the conditional.

If you wanted to print the array instead of either the first element of the array or the number of elements, print takes a list and you can cast @tab into a list as:
   print (@tab,"\n");

When I did this it jammed the elements of the array all together as:

3 567 109
and I solved that with:
   print join(' ',@tab,"\n");
</blockignore>

Finally, just for fun I turned it into a one-liner. This risks encouraging some bad programming (I didn't use strictures in my one liner), but it takes advantage of several things. perl -n replaces the outer while (<TAB>) loop. perl -a automatically spilts it for you into an array, @F. perl -l automatically handldes the newline when printing. This was on Win32, so your delimeters may vary (YDMV?).

C:\chas_sandbox>type test653837.txt 3 5 6 7 2 22 222 10 9 C:\chas_sandbox>perl -lane "$seed = 1.04 unless $seed;$diff=$F[0]-$see +d;if ($dif f>=0.1) {print join(' ',@F);$seed=$F[0];}" test653837.txt 3 5 6 7 10 9


I humbly seek wisdom.

In reply to Re: Simple iteration problem by goibhniu
in thread 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.