$_='Not Another Hacker Just Perl'; @m=qw;& 3 1 4 2;;sub a(@){$,=$";shift=~m%$"@m$%;@_} $"=q*,$*;print eval's@^.*$@$"=" "@me;@m=("(.*)")x$#m;a $'."@m";

The Spoiler

First, let's reorganise it slightly and remove any odd quoting characters:

sub a(@){$,=$"; shift =~ /$"@m$/; @_} $_='Not Another Hacker Just Perl'; @m=qw(& 3 1 4 2); $"=',$'; print eval's/^.*$/$"=" "/me; @m=("(.*)")x$#m;a $'."@m";

First, we put some text into $_, then we fill an array with & and some numbers. Then we change the special variable used when interpolating arrays into strings into ,$. If you look at the end of the eval, we have ."@m". This causes that last line to look like this:

print eval 's/^.*$/$"=" "/me; @m=("(.*)")x$#m;a $&,$3,$1,$4,$2';

When we eval that, we first do a seemingly pointless regex, this serves to put all of $_ into the $& variable and it also sets a new value for $". We then change @m to be an array containing 4 items, each being (.*). Then we execute the subroutine a, the output of which is given to the print command.

Looking at the sub:

sub a(@){$,=$"; shift =~ /$"@m$/; @_}

First, we make it operate on lists, removing the need for brackets around arguments when we call it in the eval. We then alter $, to be a space (using $" from the eval). This will cause space to be used between the elements of the returned value of the sub when it is printed. Rewriting the sub with the actual variables used gives:

sub (@) {$& =~ / (.*) (.*) (.*) (.*)/; return ($3,$1,$4,$2) }

The whole thing then simplifies to:

sub b(@) {shift =~ / (.*) (.*) (.*) (.*)/; @_} $, = ' '; print b 'Not Another Hacker Just Perl', $3, $1, $4, $2;

As @_ is an alias for the variables passed to the subroutine, and the regex has modified these $<digit> values, then @_ is used to put our four magic words in the right order.

print "Just Another Perl Hacker";

In reply to RE: A Re-Ordering JAPH (Spoiler) by quidity
in thread A Re-Ordering JAPH by quidity

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.