Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Wow, this was a good one. I stared at it blankly for 10 minutes before deciding to whip out the ol' -MO=Deparse. thelenm++

Spoiler below...

Let's start in the middle.

q=qr!J& $s[l?P^h%t:r] @e(afk)nOrbadc/oge; } #u0t4h8ex,=
Owing to the single-quote operator, q{}, this is actually building a string, using = as delimiters. It creates a very ugly looking string.

Next we see this, attached to the end of our ugly string:

=~m"\C|0xaf3d!until$a+=$b; # secret key: "g
A regex, delimited by ". The /g modifier on the end means we're matching this as many times as we can. Now notice the very first item in the regex: \C. This matches "a single C char" according to perlre. This will always match, meaning everything after the | is just filler. So we build a string and match on it. Big deal. Well, working backward through the line, just before the ugly string we see:
%==our_ugly_string_being_matched_on
So we perform a character by character match on this string and then assign the result to the %= hash. But what is being assigned? Since assigning to a hash puts us in list context, the match returns a list of matches. And since it matches every character, we're really just returning our ugly string split into characters, as if we'd done split('',ugly_string).

Now think about what the hash %= contains. The keys are every other character from our ugly string. The 1st, 3rd, 5th, etc. The odd number characters are keys. So the even numbered characters become values of those keys. Example:

$={'q'} eq 'r' $={'!'} eq 'J' $={'&'} eq ' ' $={'$'} eq 's' etc

Next we sort %=:

sort%=
This flattens %= back in to a list and sorts it. This really gives us a sorted list of the characters from the ugly string. Now here comes the tricky part:
print @={our_sorted_list_of_chars}
That kind of looks like an assignment, but remember that @ in front of an array or hash name is the way to define a slice. So do we have an array or hash named =? Yes! Remember, we assigned our unsorted list of letters to it above. In fact, the way to define a hash slice is just so: @hash{'key5','key6','key7'}. So this last bit takes a slice from %= using as keys, all of the characters from our ugly string. Half of those letters actually exist as keys in the hash (the odd letters), and the other half do not exist as keys (the even letters, they were made into values). Within the slice, the letters that are not keys will return undef list items, and the keys that are found return their values. Those values are the even numbered letters from the string, all of them. And they'll be in order of the sorted order of their keys. You guessed it: when the keys are sorted, their values spell out "Just another Perl hacker,", which is the list returned from the slice, and that is what gets printed.

kelan


Yak it up with Fullscreen ChatBox


In reply to Re: Just another JAPH by kelan
in thread Just another JAPH by thelenm

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, 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, 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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (3)
    As of 2020-03-29 00:58 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      To "Disagree to disagree" means to:









      Results (168 votes). Check out past polls.

      Notices?