Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Twin-lines japh

by ambrus (Abbot)
on Jun 14, 2007 at 16:08 UTC ( [id://621278]=obfuscated: print w/replies, xml ) Need Help??

With a big thanks to Jenda for noticing this perl syntax,

($_=Just,$\="l hacker")=~(S_&&y,Jk csluath, hate Porn,),print, ($_=Just,$\="l hacker")=~($_&&y,Jk csluath, hate Porn,),print,

Replies are listed 'Best First'.
Re: Twin-lines japh
by blazar (Canon) on Jun 19, 2007 at 08:05 UTC
    ($_=Just,$\="l hacker")=~(S_&&y,Jk csluath, hate Porn,),print, ($_=Just,$\="l hacker")=~($_&&y,Jk csluath, hate Porn,),print,

    ++, very Abigail-ish IMHO: it neither really features data nor logic obfu, in the sense that it's easy to see where the data is and have at least a naive understanding of what the logic does, but it's surprising that is works at all that!

    The japh is a single statement, composed of four comma separated expressions. The first one is

    ($_=Just,$\="l hacker")=~(S_&&y,Jk csluath, hate Porn,)

    On the lhs $_ and $\ are assigned 'Just' and 'l hacker' respectively and $\ is returned by the comma operator in scalar context and then is bound to the expression on the rhs. The latter is equivalent to (but more funny than - thanks to a savvy choice of the order of charachters)

    'S_' && tr/ Jachkls-u/a otnh erP/)

    and since S_ is a true constant, the transliteration is carried on, which makes 'l hacker' into ' another', just as if 'S_' && were not there at all.

    Actually, this was the most surprising part for me, that is that you can use a complex expression on the rhs of =~: in fact I most often rely on aliasing to $_ and implicit operation of matches, substitutions and transliterations on it, but retrospectively it's very perlish and obvious that an expression would be allowed to. To quote from perldoc perlop:

    Here, the crucial point is that S_ is a (bareword) constant, hence the emphasis above. (Is this to be considered a side effect of a compile time optimization?) In fact, passing to the second line, it's just the same as the first one except for having $_ instead of S_. In which case the full expression

    $_ && tr/ Jachkls-u/a otnh erP/)

    is evaluated and its return value applied as pattern march, which does nothing. But as a side effect the same transliteration as above is applied, this time implicitly to $_ which makes 'Just' into ' Per' and leaves 'l hacker' untouched.

    Thus, all in all, the two prints print respectively 'Just another', ' Perl hacker'.

Re: Twin-lines japh
by ambrus (Abbot) on Jun 28, 2008 at 09:18 UTC

    There's a current discussion on perl5porters about how /$x/ behaves specially when $x is empty (and this is true to /\Q$x/ as well). That magic is totally way crazyer than the one I'm using in this obfu (or the similar one in Re^3: A cleaner way of scoping variables; or the one you get if you combine either of these with inlined constant subroutines). My obfu is topped.

Re: Twin-lines japh
by ambrus (Abbot) on Oct 21, 2010 at 14:38 UTC

    P5p have decided that the feature I'm using here is a bug, and so perl 5.13.6 breaks this obfu. Try this quickily while it still works.

Log In?
Username:
Password:

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

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

    No recent polls found