[comp.lang.perl] uusched.sh: a shell script to replace broken uuscheds

lwall@jato.Jpl.Nasa.Gov (Larry Wall) (05/04/90)

In article <11614@netcom.UUCP> gam@netcom.uucp (Gordon Moffett) writes:
: I'd like to see other ways of doing what 'shuffle' does, as long as it
: allows for completely random results, like the last line of input
: being the first line of output.
: 
: #!/bin/sh
: # xshar:	Shell Archiver  (v1.22)
: #
: #	Run the following text with /bin/sh to create:
: #	  shuffle
: #
: sed 's/^X//' << 'SHAR_EOF' > shuffle &&
: Xawk "BEGIN { srand($$) } { print int(rand()*1000000), \$0 }" $* |
: Xsort -n |
: Xsed 's/^[0-9]* //'
: SHAR_EOF

You are lost in a maze of twisty little pipes, all alike.

How about:

#!/usr/bin/perl
srand; @x=<>; print splice(@x,rand @x,1) while @x;

Of course, it's silly to go to all that effort just to pick one line.
You do that like this:

#!/usr/bin/perl
srand; @x=<>; print $x[rand @x];

Of course, if you really like to start zillions of processes, don't let
me stop you...

Larry Wall
lwall@jpl-devvax.jpl.nasa.gov