Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Continuing While Loop One Iteration After EOF

by Eimi Metamorphoumai (Deacon)
on Dec 22, 2005 at 16:57 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://518585]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-25 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found