in reply to scramble text simply

I guess I'm a bit bored, today, because I came up with another way:
perl -e "print sort {rand > .5} split //, qq(More Text)"
Update: That probably should have been:
perl -e "print sort {rand <=> .5} split //, qq(More Text)"

Replies are listed 'Best First'.
Re:x2 scramble text simply (don't feed sort weird codeblocks)
by grinder (Bishop) on Oct 03, 2003 at 21:31 UTC
    sort {rand > .5}

    That's a bad way to scramble text, because it uses a bad method of performing a sort. The documentation makes the following point:

    The comparison function is required to behave. If it returns inconsistent results (sometimes saying $x[1] is less than $x[2] and sometimes saying the opposite, for example) the results are not well-defined.

    The usual definitions of not well-defined include dumps core and fails to terminate. It might work, but only by luck.

      Thanks for the cautionary note!

      I wonder if the inconsistency might cause the sort to continue making swaps indefinitely, thus causing the failure to terminate that you mentioned?

      Of course, my simple test case did just fine, but that probably was dumb luck.