in reply to Re: fun with subroutines
in thread fun with subroutines

Yes, that's it pretty much exactly.
As far as getting into the internals with sort, just told Perl to sort{1}split//,"Just another Perl hacker.\n", printed the result (assigned to an array and interpolated), and then worked out from the ordering it produced where it was moving things, and where I had to put them to get the right order.

Replies are listed 'Best First'.
Re: Re: fun with subroutines
by nothingmuch (Priest) on Apr 17, 2003 at 00:24 UTC
    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

      I've found a more portable way to abuse sort: use a sort function that does result in a defined order, but obfuscate it. For a (quite rudamentary) example, see my new signature:

      {my$c;$ x=sub{++$c}}map{$ \.=$_->()}map{my$a=$_->[1]; sub{$a++ }}sort{_($a->[0 ])<=>_( $b->[0])}map{my@x=(& $x( ),$ _) ;\ @x} split //, "rPcr t lhuJnhea eretk.as o";print;sub _{ord(shift)*($=-++$^H)%(42-ord("\r"))};

      Of coures, for serious obfuscation something much more obscure than modular arithmetic would be called for in the sort function, but this is just a JAPH.