in reply to While loop conditions in Perl
A more perlish way to do this, and the way that confines your variable to the scope of the loop, is like this:
while( my $nextline = <IN> ){ chomp; last unless $nextline eq ''; # exits the loop unless empty line print "Nextline is empty\n"; } # now $nextline goes out of scope
UPDATE: Yes, as cheekuperl noticed, that should be chomp $nextline;
Aaron B.
Available for small or large Perl jobs; see my home node.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: While loop conditions in Perl
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 cheekuperl (Monk) on Aug 09, 2012 at 07:59 UTC | |
by Anonymous Monk on Oct 18, 2013 at 21:31 UTC |