in reply to Re^2: reading lines from a text file
in thread reading lines from a text file

($nextline=~/$SearchString/)

Is it maybe that you have the comparison wrong? You are comparing whether $nextline matches /$SearchString/. I interpret your description as that you want to stay in the loop while $nextline does not match /$SearchString/:

($nextline!~/$SearchString/)

Replies are listed 'Best First'.
Re^4: reading lines from a text file
by misba (Initiate) on Dec 27, 2008 at 10:53 UTC
    You are right, I want to stay inside inner while loop until nextline matches search string. But lets forget my code, I am just looking for an answer to this:
    while($line=<FH>) { while($nextline=<FH>) { .... } }
    Is this possible, I mean, does the inner "while loop" help me to read next line in the file. How can I read next line in a file, being inside first "while loop". I dont want to break first while loop. Thanks.
      You can answer that for yourself by using
      while($line=<FH>) { print("outer: $line"); while($nextline=<FH>) { print("inner: $nextline"); } print("finished inner\n"); } print("finished outer\n");
        by calling while() inside the while() you are looping in side the line for every line.

        but if you have some 'standard' separators in your file you could loop between separators with while loop, by defining the separators with special variable $/ something like :

        open (FILE, "<", $ARGV[0]) || die "$!"; $/ ="seperator"; while (<FILE>){ ## process lines between separators but don't forget that you define +d record separator as "separator" !!! } $/ = "\n"; # return the record separator to standard or if it is a st +and alone script this is not necessary because you are finished