Re: newbie: foreach
- From: miguel sofer <msofer@xxxxxxxxxxxx>
- Date: Tue, 16 Aug 2005 18:37:11 -0300
miguel sofer wrote:
Kev P. wrote:
I'm sure the below can be simplified with some sort of "foreach", but so far I've failed. Anyone help please? Snippet of code attached:
The use of foreach and arrays has been illustrated by the previous replies; I just want to suggest replacing your busy loop with an event-based processing. The difference is that your script will take as much cpu as available while waiting for user input, and this will just idle.
Pardon my ignorance but I thought that in the original code the line "gets stdin line" will block inside the OS and not consume cpu cycles.
Indeed, I somehow forgot that stdin is blocking by default :(
I (tried) to delete that message right after noticing my boo-boo, and sent another message with essentially this remark.
Ever so sorry, my bad.