UPDATE: I am an idiot, in my code I did a copy paste error and reinstantiated my nextline inside the while loop with...
while(...) { my $nextline = <IN> ..... }
That I am assuming was scoped within the while loop. So I guess if a mod could delete this, that would be super.
So I am trying to write some code to skip over empty lines in some rather large files, so I am trying...
my $nextline = <IN>; while($nextline eq '') { $nextline = <IN>; print"Nextline is empty\n"; }
If I am reading a file with EMPTY LINE,EMPTY LINE,EMPTY LINE,EMPTY LINE,4,5 and 6 each on a new line.
my print statements will be
Nextline is
Nextline is
Nextline is
Nextline is
Nextline is 4 # SHOULD EXIT THE WHILE LOOP
Nextline is 5 # BUT STILL IN IT
Nextline is 6 # STILL IN IT!
So my nextline is getting updated correctly, but it doesn't seem that the condition for the while loop is using it?
I know my logic is right since if I insert an if stmt that checks the same conditon...
... if($nextline ne '') { last; } ...
It exits exactly how I want it to. So I am assuming conditions for while loops in perl are not behaving as one would normally expect.
In reply to While loop conditions in Perl by joemaniaci
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |