Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Pe(a)rls in line noise

by liz (Monsignor)
on Sep 13, 2003 at 16:47 UTC ( #291267=obfuscated: print w/replies, xml ) Need Help??

@;=(491036,8051555,4785250,3341086,912133,189089,691108),%;=eval{qw; He didn't,Just do to,Perl didn't understand,another it would,hacker! ;};{/./?{[(eval{[eval(join't, ',qw:prin exi delphi:)]})]}:/./;%:=qw; ================================= ================================== Randal said it would be tough to do in sed. He didn't say he didn't understand sed. Randal understands sed quite well. Which is why he uses Perl. :-) -- Larry Wall in <7874@jpl-devvax.JPL.NASA.GOV> ================================= ================================== ;;$:{do}=to;@;=map{join',',q&&,$_,''}values(%;);eval'$:{q?'.$_.'?}=~ s'.shift@;for keys(%;);$_=qq{@{[@:{qw{ He didn't do it }}]}},redo}x:


Replies are listed 'Best First'.
Re: Pe(a)rls in line noise
by Roger (Parson) on Sep 15, 2003 at 06:28 UTC
    Hi Liz, this is my attempt at decoding this clever JAPH, in fact my first attempt at decoding any JAPH, so please correct (and forgive) my analysis if wrong!

    @; = (491036,8051555,4785250,3341086,912133,189089,691108);
    # This is just an eye candy, an array placeholder of 7 elements
    %; = qw/ He didn't,Just do to,Perl didn't understand,another it would,hacker! /;
    # This constructs the %; hash variable with 4 entries, namely He, do, didn't, it:
    He => didn't,Just do => do,perl didn't => understand,another it => would, hacker!
    %: = qw/ ================================= ================================== Randal said it would be tough to do in sed. He didn't say he didn't understand sed. Randal understands sed quite well. Which is why he uses Perl. :-) -- Larry Wall in <7874@jpl-devvax.JPL.NASA.GOV> ================================= ================================== /;
    This builds another hash lookup - %:
    { # required by redo, where to start for the redo /./ ? eval(join 't, ', qw:prin exi delphi:) : /./;
    This is really (translated to):
    /./ ? { print, exit, delphit, } : /./;
    or just
    /./ ? { print, exit, } : /./;
    Clever, the first time this loop is enterred, $_ is undef, so the print and exit is not performed. delphit would have no effect (after the exit).
    $:{do} = 'to';
    # Another clever bit, insert the required 'do=>to' lookup pair into the hash table. How this is used will be explored later.
    @; = map { join ',', '', $_, '' } values(%;);
    Translates the values to the %; hash to ",xxx,", required by the lookup below
    This translation is clever:
    The key-value pairs in the %: hash so far
    He => didn't didn't => understand do => to # manually inserted before it => would
    And then... Modify the hash table %:, with values from the %; lookup.
    eval '$:{q?'.$_.'?}=~s'.shift@; for keys(%;);
    So that:
    He => Just didn't => another do => Perl it => Hacker!
    This next bit just creates the string to be printed. :-)
    $_ = qq{@{[@:{qw{ He didn't do it }}]}};
    The next bit goes back to the beginning of the loop, with $_ set to "Just another Perl hacker!", and of cause the print, exit, code will take over from there...
    redo } x: first attempt at decoding any JAPH...

      Well, you're in good company then, because this was the first JAPH I ever made myself. Honest!

      @; = (491036,8051555,4785250,3341086,912133,189089,691108);
      Yep, that's just eye candy. There have been some JAPH's recently that used magical increment for an X number of times, and I was going for similarly looking numbers. The:
      ================================= ==================================
      and at the end: x: are also just eye candy. I tried several Larry Wall quotes while building this japh, and the line with '=====' made it possible for me to easily switch between keys and value in the hash (change the space between the "==="'s to "=" and all keys are values and vice versa in the hash).

      $:{do} = 'to';
      was actually a kludge. Originally I had the "to do" exchanged in the quote. But I found the error in the quote too obvious.

      eval '$:{q?'.$_.'?}=~s'.shift@; for keys(%;);
      This actually works because whatever order hash keys have in a hash, the order returned by the "keys()" and "values()" functions is the same. And for some reason, I _had_ to put parentheses with keys() and values() because otherwise I was getting the warning that the call was ambiguous. That's still on my list to check out later.

      $_ = qq{@{[@:{qw{ He didn't do it }}]}};
      is what you call an interpolated anonymous hash slice ;-) Working from the outside in: the qq{...} creates an interpolated string, which will put spaces between the elements because $" was not changed. The @{...} dereferences an array reference. The [...] create a reference to an array. The @:{...} creates a hash slice on %:. And finally the qw{...} creates the array of keys for the hash slice.

      ...cause the print, exit, code will take over from there...

      I don't know if that is what you meant to say, but after the "exit" there is no code to execute anymore. So the "x:" is never reached, it's just eye candy.


        Hi Liz, thanks for your reply and detailed analysis!

        The biggest benefit I got from this is the anonymous hash slice bit. Normally I would have written something that joins the values of a hash as

        $_ = join " ", map { $:{$_} } qw/ He didn't do it /;

        Now I have learnt an ideomatic way to do it. Thanks!
Re: Pe(a)rls in line noise
by woolfy (Hermit) on Sep 13, 2003 at 16:58 UTC
    Well, I've got no clue... I've read the article from which you quote. I've met Larry and Randal. But I'm sure they never expected this! Nice obfu. Your first japh! To celebrate holiness?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://291267]
Approved by Mr. Muskrat
Front-paged by jeffa
[Corion]: Meh. I think I have now the parts down that I want from a simple Javascript frontend for single-page- applications with a aPerl backend. But it seems that all Javascript templating modules either don't support two-way binding (which would be nice) or ...
[Corion]: ... don't support server-side precompilation (which means the client has to compile all templates to Javascript themselves), or are giant frameworks that expect to do everything (which is not what I want)
[Corion]: I feel that there is a talk somewhere in there, either about the structure and parts, or how I used several parts to get a complete whole.
[Corion]: Maybe I can still find something that is compatible with handlebars.js (which has JS precompilation) but allows for two-way data binding (which is great for the UI)

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2017-03-30 07:50 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (355 votes). Check out past polls.