Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Well, the code actually wasn't intended to be obfuscated. I've never had much of an interest in writing obfuscated perl, and haven't read the node you mentioned. (Although I expect I will as soon as I'm done posting my reply....)

I started with the mere idea that I wanted to write "My Bonnie Lies Over the Ocean" as a perl poem, and just tried my hardest to force the poem to be syntactically valid. I will admit that it turned out better than I expected. Here's a collection of thoughts that might help to explain how it got into its final form.

I started with:

my $bonnie = "lies_over_the_ocean"; my $bonnie = "lies_over_the_sea"; my $bonnie = "lies_over_the_ocean";
Of course, the compiler complained about multiple declarations of $bonnie within the same scope, so I merely added the requisite braces to make each $bonnie declaration fall into a new scope.

The 0; before the first bring_back() is simply a no-op. It's there because the actual song contains the word "oh" at that point.

I noticed that the words "bring back" are used repeatedly throughout the song, and made an analogy between lyrics and code. As a rule, oft-used pieces of code should be stuck within a function. Hence, I created a bring_back() function and called it repeatedly. It just "worked out" to have nested calls to bring_back(), since that fits the flow of the actual song. The calls to bring_back() have the added advantage of setting up new scopes such that I can declare $bonnie again. The 0,'s within the function calls continue the tradition set up earlier; they use the number 0 to represent the phonetic "oh"'s that are present in the real song, while keeping the code syntactically valid.

I called each bring_back() with whatever arguments fit the song.

At this point, I created an empty sub bring_back {} that did nothing, and thought my work was done.

I then decided it would be nice for the poem to actually output something, and decided that bring_back() should be the place to do it. The obvious problem was getting the output to print only once, since bring_back() gets called 7 times. I decided I'd use the number of arguments passed to bring_back() as the criteria for printing, and simply toyed with bring_back()'s return value until I got a unique number of arguments passed (5) on the last call.


In reply to Obfuscation? by Falkkin
in thread my $bonnie by Falkkin

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



  • 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> <u> <ul>
  • 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 intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 21:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found