Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

A Re-Ordering JAPH

by quidity (Pilgrim)
on Oct 21, 2000 at 05:06 UTC ( [id://37767]=obfuscated: print w/replies, xml ) Need Help??

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

I have also written a spoiler as a reply.

Replies are listed 'Best First'.
RE: A Re-Ordering JAPH (Spoiler)
by quidity (Pilgrim) on Oct 21, 2000 at 05:28 UTC
    $_='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";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://37767]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-23 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found