#! perl -slw use strict; use List::Util qw[ shuffle ]; ## omit the glob if your shell expands wildcards for you. BEGIN{ @ARGV = shuffle map glob, @ARGV } print ~~localtime; my @temps; open $temps[ $_ ], '> :raw', "tmp/$_.tmp" for 0 .. 99; while( <> ) { printf { $temps[ rand 100 ] } $_; } print 'Temp files written'; do{ close $temps[ $_ ]; open $temps[ $_ ], '< :raw', "tmp/$_.tmp" or die "tmp/$_.tmp : $!" ; } for 0 .. 99; open FINAL, '> :raw', "randomised.all" or die $!; while( @temps ) { my $pick = int rand @temps; printf FINAL scalar readline( $temps[ $pick ] ); if( eof $temps[ $pick ] ) { close $temps[ $pick ]; undef $temps[ $pick ]; splice @temps, $pick, 1; } } close FINAL; print ~~localtime; __END__ P:\test>perl -le"printf qq[%030d\n], $_ for 1 .. $ARGV[ 0 ]" 100 > junk P:\test>389660 junk Wed Sep 15 14:25:59 2004 Temp files written Wed Sep 15 14:25:59 2004 P:\test>perl -le"printf qq[%030d\n], $_ for 1 .. $ARGV[ 0 ]" 1000 > junk P:\test>389660 junk Wed Sep 15 14:26:08 2004 Temp files written Wed Sep 15 14:26:08 2004 P:\test>perl -le"printf qq[%030d\n], $_ for 1 .. $ARGV[ 0 ]" 10000 > junk P:\test>389660 junk Wed Sep 15 14:26:17 2004 Temp files written Wed Sep 15 14:26:18 2004 P:\test>perl -le"printf qq[%030d\n], $_ for 1 .. $ARGV[ 0 ]" 100000 > junk P:\test>389660 junk Wed Sep 15 14:26:26 2004 Temp files written Wed Sep 15 14:26:33 2004 P:\test>perl -le"printf qq[%030d\n], $_ for 1 .. $ARGV[ 0 ]" 1000000 > junk P:\test>389660 junk Wed Sep 15 14:27:02 2004 Temp files written Wed Sep 15 14:28:05 2004 P:\test>perl -le"printf qq[%030d\n], $_ for 1 .. $ARGV[ 0 ]" 20000000 > junk Terminating on signal SIGINT(2) P:\test>perl -le"printf qq[%030d\n], $_ for 1 .. $ARGV[ 0 ]" 10000000 > junk P:\test>389660 junk Wed Sep 15 14:30:17 2004 Temp files written Wed Sep 15 14:42:40 2004