Put the following in a file,
defined(my $v = <>) or exit; my ($c,@c) = 1; open($_, "|-", "$^X $0") for @c[0,1]; $_ eq $v ? ++$c : print { $c[ $_ lt $v ] } $_ while <>; pop @c; print $v x $c;
, and run it with an unsorted text file either on stdin, or as a command line argument. The output will be sorted.

Replies are listed 'Best First'.
Re: Fork Sort
by RMGir (Prior) on Jun 01, 2014 at 23:32 UTC
    Very nice! I had a pretty good idea what algorithm was being used, but it took some reformatting and extra prints before I figured out how it was happening.

    Here's the reformatted version behind the spoiler protection.


    Mike