Sometimes obfu just happens. But unexpected obfuscation is most likely to happen when trying to play interesting games with control of flow.

I still remember with my shock reading an early version of Switch and encountering the line, goto $__;. After discussion with TheDamian I realized that he was right, there was no other way to achieve the promised control of flow. (One of two necessary uses of the traditional goto that I know of in Perl! Bonus points to anyone who can guess the other.)

In fact that line is still there, but thankfully $__ has a better name.

For another view of how one might implement goto in a language which doesn't support it, see Coroutines in C. The technique presented there is actually used in a popular piece of software. (PuTTY. If you're on Windows and need a decent ssh client, get it.) That article is aimed at C, and uses the pre-processor to work its magic.

He also accidentally wound up obfuscating his code. So much so that he felt compelled to write an article explaining why his approach really was natural and obvious, despite the obvious things which people can object to in it.


In reply to Re: Coroutines by tilly
in thread Obfu Coroutines by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.