in reply to reading lines from a text file

Here is my try using threshold count
my $threshold = 0; while($line=<FH>) { if($line=~ /$SearchString/) { $threshold++; } last if ( $threshold eq 2 ); # continue processing }

Replies are listed 'Best First'.
Re^2: reading lines from a text file
by tilly (Archbishop) on Dec 27, 2008 at 15:13 UTC
    It should be habit for you to write
    while (my $line = <FH>) { .... }
    because you should always use strict.pm. Right?
      You got that right and I didn't mean to do that.

      I just copied, pasted the sample code posted and modified the version with my logic.

      But anyway, I should have properly given the code snippet.

      Thanks for pointing it out and correcting :)
Re^2: reading lines from a text file
by misba (Initiate) on Dec 27, 2008 at 11:37 UTC
    thanks guyz for ur replies... i got what i wanted to do.. here is the sample code:
    while($line=<FH>) { print "$line \n"; while(<FH>) { print "Next line is $_ \n"; } }
    Using $_ worked for me in my application. I replaced variable $nextline with $_, so that the inner "while" works with $_ until the condition and $line will continue from where $_ left ( i.e. file handler). Thanks once again guyz. take care and have fun
      Random tips. You should use strict.pm which means you want a my in declaring $line. Also an 8-space indent is too much - in studies comprehension is best with an indent of 2-4 spaces. (There seems to be a marginal benefit to 4 spaces.)

      Sure, these points may look picky. But a good style comes from consistency on trivial details.