I find co-routines useful, especially as filters or as generators for use in a loop. But their internal implementations can be ugly. While it would be nice to have them in this language, “there’s more than one way to do it.™” As BrowserUK says (in so many words), I would not disabuse the Perl-5 language in order to do it in just this way.
For example, there are already closures in Perl ... the “coderefs” that were mentioned ... and these can be used to implement finite-state machines (FSMs) which will return a particular value each time they are called. Presto, you have accomplished the intended effect, using the ordinary facilities that this programming language already offers you. No, it’s not exactly the same thing, but a well-written implementation is clear. Bloom where you are planted.
Anyhow, there are other threads on this, like Coroutines in Perl from back in 2004 ... and I can’t help but notice that, even “way back then,” the Perl-6 / Parrot people were telling us all how good it was going to be. Someday. ;-)
Are you posting in the right place? Check out Where do I post X? to know for sure.
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
Want more info? How to link or
or How to display code and escape characters
are good places to start.