Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Play random music

by Fingo (Monk)
on Mar 24, 2001 at 07:35 UTC ( [id://66823]=perlcraft: print w/replies, xml ) Need Help??

   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: }

Replies are listed 'Best First'.
Re: Play random music
by methodius (Initiate) on Apr 08, 2001 at 10:32 UTC
    When I'm writing a daemon will drop a file ususally based on the PID $$ and then inside the loop test for the existence of the file and exit if the file is deleted:

    open PID,">$$" or die $@;
    close PID;

    while (-e $$) {
    do_good();
    }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 00:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found