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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.