$_='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"; |