e = EventLog.open("Application")
e.tail{ |rec|
puts "Record added to log"
p rec
}
The tail method sits in an infinite loop (which is accomplished with the 'goto'), yielding a (custom) struct every time a record is written to the event log.
On a stranger note, the Windows function NotifyChangeEventLog() can only detect a maximum of one change every five seconds. That means, even if 20 records were written to the event log in under 5 seconds, that block would only pick up the first one. No, there's no way around it.
I don't see the goto (Score:1)
For the record, I know of exactly two necessary uses of goto in Perl.
Re:I don't see the goto (Score:2)
Re:I don't see the goto (Score:1)
Secondly I don't see why you aren't using while to get the infinite loop rather than goto.
Thirdly you can save some lines by not always using braces. For instance:
Re:I don't see the goto (Score:2)
I said is was a C extension for Ruby. I showed you the frontend. The C code above is the backend.
Secondly I don't see why you aren't using while to get the infinite loop rather than goto.
I suppose I could have done while(1) or something. It just didn't feel right.
Thirdly you can save some lines by not always using braces.
I hate that, sorry.
Re:I don't see the goto (Score:1)
About the second. I'd suggest re-reading Go To Statement Considered Harmful [acm.org]. The fact that your indentation and control structures are in conflict makes your program's flow of control harder to understand upon first reading. Even if you aesthetically prefer a goto to an infinite while loop, I'd suggest that you indent from the label to the goto so that that section jumps out at the maintainer.
Re:I don't see the goto (Score:2)
Roger that. :)