Syntactic Confectionery Delight | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Since I left these out of the code I posted, and since some people did not follow the Help Name This Module thread, here is some documentation for the Loop::Watch module.
AbstractLoop::Watch is like alarm() for variables -- it watches a given set of variables (scalars, arrays, and hashes are the only ones currently supported), and exits a block of code (which may or may not be a loop) as soon as the condition it is given becomes false. It's like a while-loop that keeps tabs on the condition constantly.UsageLet's say you wanted to do a series of statements, but stop as soon as one of them caused $temperature to go below 0, and if none caused that, to continue normally with the rest of the program.That code would probably stop somewhere around the move to New Jersey. That function could do any number of things to $temperature, and this module keeps an eye on things. Let's say, though, you wanted to circle the globe until your money ran out: This allows the functions called by circle_globe() to assume you have money left -- and as soon as you don't have any money left, you stop your trip. You can watch multiple variables in the same block: That code will stop once you've reached 35 (good age to retire at) or you've acquired 10 companies. Maybe during the course of the new_year(), you lose a company or something -- that's ok. You needn't do any checking there, all the checking of the age and company count is done by the module. japhy -- Perl and Regex Hacker In reply to Docs and Examples for Loop::Watch
by japhy
|
|