DentArthurDent has asked for the wisdom of the Perl Monks concerning the following question:
If it makes any difference, this is Perl 5.8.5 on SuSE Linux 9.2.#!/usr/bin/perl use Data::Dumper; open(PLAYLIST,"</somedir/myplaylist.lst"); my @songs; while (<PLAYLIST>) { chomp(); push(@songs,$_); } my $count = scalar(@songs); print "We found $count songs\n"; while (scalar(@songs) > 0) { my $song_num = rand(scalar(@songs)); print "*** Playing $songs[$song_num]\n"; `mpg321 '$songs[$song_num]'`; splice(@songs,$song_num,1); }
#!/usr/bin/perl my $song_num; my @songs; my $pid; sub catch_next { my $signame = shift; print "Going to next song!\n"; my $count = kill(15,$pid); } sub reaper { $waitedpid = wait; $SIG{CHLD} = \&reaper; } open(PLAYLIST,"</somedir/myplaylist.lst"); while (<PLAYLIST>) { chomp(); push(@songs,$_); } $SIG{INT} = \&catch_next; $SIG{CHLD} = \&reaper; my $count = scalar(@songs); print "We found $count songs\n"; while (scalar(@songs) > 0) { $song_num = rand(scalar(@songs)); my $song = $songs[$song_num]; splice(@songs,$song_num,1); print "*** Playing $song\n"; unless ($pid = fork) { exec("mpg321", "$song"); } waitpid($pid,0); }
#!/usr/bin/perl my $song_num; my @songs; my $pid; sub catch_next { my $signame = shift; print "Going to next song!\n"; my $count = kill(15,$pid); } open(PLAYLIST,"</somedir/myplaylist.lst"); while (<PLAYLIST>) { chomp(); push(@songs,$_); } $SIG{INT} = \&catch_next; my $count = scalar(@songs); print "We found $count songs\n"; while (scalar(@songs) > 0) { $song_num = rand(scalar(@songs)); my $song = $songs[$song_num]; splice(@songs,$song_num,1); print "*** Playing $song\n"; unless ($pid = fork) { exec("mpg321", "$song"); } waitpid($pid,0); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Can I stop a backtick command but continue the script?
by RazorbladeBidet (Friar) on Mar 02, 2005 at 17:59 UTC | |
Re: Can I stop a backtick command but continue the script?
by bluto (Curate) on Mar 02, 2005 at 21:08 UTC | |
by DentArthurDent (Monk) on Mar 03, 2005 at 12:47 UTC | |
Re: Can I stop a backtick command but continue the script?
by dmorelli (Scribe) on Mar 02, 2005 at 18:11 UTC | |
Re: Can I stop a backtick command but continue the script?
by zentara (Cardinal) on Mar 03, 2005 at 12:32 UTC | |
Re: Can I stop a backtick command but continue the script?
by saintmike (Vicar) on Mar 02, 2005 at 23:01 UTC | |
Re: Can I stop a backtick command but continue the script?
by tphyahoo (Vicar) on Mar 03, 2005 at 11:06 UTC |