joemaniaci has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: While loop conditions in Perl
by cheekuperl (Monk) on Jul 18, 2012 at 21:35 UTC | |
|
Re: While loop conditions in Perl
by aaron_baugher (Curate) on Jul 18, 2012 at 21:50 UTC | |
by cheekuperl (Monk) on Jul 18, 2012 at 22:09 UTC | |
by joemaniaci (Sexton) on Jul 18, 2012 at 22:20 UTC | |
by cheekuperl (Monk) on Jul 19, 2012 at 06:00 UTC | |
by SuicideJunkie (Vicar) on Jul 19, 2012 at 14:41 UTC | |
by joemaniaci (Sexton) on Jul 20, 2012 at 16:06 UTC | |
| |
by Anonymous Monk on Oct 18, 2013 at 21:31 UTC | |
|
Re: While loop conditions in Perl
by Kenosis (Priest) on Jul 18, 2012 at 22:23 UTC | |
|
Re: While loop conditions in Perl
by aitap (Curate) on Jul 18, 2012 at 21:49 UTC | |
by Anonymous Monk on Jul 19, 2012 at 14:38 UTC | |
by aitap (Curate) on Jul 19, 2012 at 16:37 UTC | |
|
Re: While loop conditions in Perl
by Marshall (Canon) on Jul 19, 2012 at 07:31 UTC |