Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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:
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 %=:

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.


Yak it up with Fullscreen ChatBox

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

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2021-05-18 06:07 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (174 votes). Check out past polls.