Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:
I'm having one of those days when my brain won't work properly. How do I write a method for my module which returns a bunch of things, not all at once at the end, but one by one as a slow process happens?
Something like what happens when I fetch from a database with DBI: while($thing = getNextThing()){ ### do something } where my getNextThing() takes a while, depends on unreliable internet access, may return 1000 things etc.
If I return my sub is finished. I need to send a bunch of things back one by one, and send undef after they're all done to stop the while.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: I want to write a method that can be used with 'while ($thing = getNextThing() )'
by choroba (Cardinal) on Aug 20, 2016 at 07:20 UTC | |
by Anonymous Monk on Aug 20, 2016 at 07:27 UTC | |
by Cody Fendant (Hermit) on Aug 20, 2016 at 11:50 UTC | |
|
Re: I want to write a method that can be used with 'while ($thing = getNextThing() )'
by kroach (Pilgrim) on Aug 20, 2016 at 10:05 UTC | |
by Cody Fendant (Hermit) on Aug 20, 2016 at 11:51 UTC |