++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:
for toolic's results, since that's the number of elements in the arrays on the lines that satisfy the conditional.1 3 2
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:
and I solved that with:3 567 109
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
In reply to Re: Simple iteration problem
by goibhniu
in thread Simple iteration problem
by Etbr77
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |