#!/usr/bin/perl -w =head1 NAME randomize [-v] file... > random_file =head1 SYNOPSIS randomize [-v] file... > random_file Options: -v Output lines to error channel too -# Limit the number of lines to output =head1 DESCRIPTION Simple perl program to completely randomize the order of the lines of all the files given. =head1 AUTHOR Anthony Thyssen =cut sub Usage { use Pod::Usage; pod2usage("@_"); exit 10; } my $lines = 0; # output all the lines in the file my $verbose = 0; ARGUMENT: # Multi-switch option handling while( @ARGV && $ARGV[0] =~ s/^-(?=.)// ) { $_ = shift; { m/^$/ && do { next }; # next argument m/^-$/ && do { last }; # End of options m/^\?/ && do { Usage }; # Usage Help s/^(\d+)// && do { $lines = $1; redo }; # number of lines s/^v// && do { $verbose++; redo }; # output to stderr too Usage( "Unknown Option \"-$_\"\n" ); } continue { next ARGUMENT }; last ARGUMENT; } # ---------------------------------------- srand($$^time); @lines = <>; # read in all lines in files given while( $#lines >= 0 ) { $line = splice(@lines, rand(@lines)+$[, 1); print $line; print STDERR $line if $verbose; last if --$lines == 0; }