http://qs321.pair.com?node_id=66823

   1: #!/usr/bin/perl 
   2: # Plays a random file from $dir using $player.  
   3: # I still have not figured a good way to quit other than killing
   4: # the perl program and then the player, anybody have some good ideas?
   5: # UPDATE: now properly replaces escape characters (old version replaced with space)
   6: use strict;
   7: my $dir = "/dosc/Music/";
   8: my $player ="mpg123";
   9: my ($i, @music);
  10: opendir (DIR, $dir);
  11: @music = readdir (DIR);
  12: closedir (DIR);
  13: foreach (@music) {
  14:     s/([\s|&|\\|\||(|)|'|_])/\\$1/g; # Add escape characters
  15: }
  16: srand();
  17: while (1)
  18: {
  19: $i = @music[int(rand(scalar(@music)))];
  20:     system "$player $dir$i";
  21: }