|The stupid question is the question not asked|
Obfu Coroutinesby Limbic~Region (Chancellor)
|on Aug 22, 2004 at 04:59 UTC||Need Help??|
How many of you have ever thought about how to implement coroutines in Perl?
Wow, I hadn't expected any. How many of you with your hands raised have thought about how you might avoid source filters and evil gotos?
Ok, with the exception of perhaps TheDamian, how many actually tried it? It seemed simple enough and I had a working solution in about 10 minutes:
The problem was that it was fugly and no longer resembled a coroutine. I figured if I put it inside a module (see below), it would hide all the nasty stuff and maybe even make it more useable.
Boy was I wrong! It came out horrendous. What, you don't believe me? Just look:
All of that to do the following if Perl natively supported coroutines:
Incidently, revdiablo and I came up with a solution using evil gotos and source filters about a week ago that was elegant.
So why post? Well even with the explanation, it isn't easy to see what is going on inside the module - especially with the bless/tie combo. I really didn't intend it to come out obfu. Sometimes obfu just happens
I originally posted this under Obfuscation, but didn't argue with Enlil when he asked to move it here. The real meditation, "Sometimes obfu just happens" along with "sometimes breaking the rules is the best way to do things" is there though - along with an attempt at some humor ;-)
Cheers - L~R