I'm starting to have fun with subroutines. Here's a little JAPH I did up to explore some possibilities.

#!/usr/bin/perl -- -*- cperl -*- sub a{my%v=map{($w[$_],$_)}@w;my$n;sub{$v{$b}<=>$v{$a}; ++$n}};sub _{my$v=shift;sub{$\=$v;$_='';}}@w=sort{&a->( $a,$b)}map{_($_)}split//,"erl hc\nker.aPust another J"; for(@w){&$_;print;}

I'm not sure how portable that is; I've only had the chance to test it on Perl 5.6.0 on Linux. The platform probably doesn't matter, but the Perl version might. Anyway, I think it shows the obfuscation potential of subroutines, especially in terms of using unnatural divisions to put things in different routines that go together and put things together that belong apart :-)

Exegesis is welcome, but stick it in readmore tags just in case people want to work it out on their own. (Not that something this short will take anyone very long...)

Update: Corrected silly sigil typo in code.

Replies are listed 'Best First'.
Re: fun with subroutines
by LAI (Hermit) on Apr 16, 2003 at 16:52 UTC

    Okay, I'll give this a shot. My first longish obfu deconstruction:

    LAI

    __END__
      Yes, that's it pretty much exactly.
        Playing with it was inspiring, and i attempted to roll my own a bit. Very fun!

        For portabilities sake you might want to use sort '_qsort', which fixed it for me, if perl 5.8.0. It's 3am, and i've just had one of the weirdest sober nights in my life, so i'm in no condition to think of how to selectively load pragmatic modules right now.

        ++ once more... and good night.

        -nuffin
        zz zZ Z Z #!perl
Re: fun with subroutines
by nothingmuch (Priest) on Apr 16, 2003 at 14:33 UTC
    Kudos on the mapped sub... a bright idea... =)

    The sort stumped me tho... You aren't comparing, but always returning one... the compare is thrown away... why so? It doesn't work on my machine (darwin), but it was a lot of fun to work out... =)

    -nuffin
    zz zZ Z Z #!perl
      You're very close to understanding the main trick.