Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Continuing While Loop One Iteration After EOF

by Eimi Metamorphoumai (Deacon)
on Dec 22, 2005 at 16:57 UTC ( #518585=note: print w/replies, xml ) Need Help??


in reply to Re: Continuing While Loop One Iteration After EOF
in thread Continuing While Loop One Iteration After EOF

That will loop through the file, but then it will continue to loop forever with 'AFTERFILE' in $_. So if you're going to do that, you'd have to do it as
while (defined($_ = <INHANDLE>) || ($_ = "AFTERFILE")){ stuff; last if $_ eq "AFTERFILE"; }
and of course, if the file actually contains AFTERFILE, you're in trouble.

So if you don't mind undef as your special after loop value, it's probably easiest to do something like

LOOP: { $_ = <>; stuff; redo LOOP if defined; }

Replies are listed 'Best First'.
Re^3: Continuing While Loop One Iteration After EOF
by traveler (Parson) on Dec 22, 2005 at 17:15 UTC
    The OP suggested AFTERFILE and that's why I said "Assuming, as you imply, that the body of the loop will know what to do when it sees AFTERFILE."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://518585]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2020-10-31 03:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (286 votes). Check out past polls.

    Notices?