As for the general structure of your code, you are right -- all those evals are atrocious. Instantiating global variables via eval as a way to implement argument passing? @file0 through @file8?? Ew.
And for prior art in the subject, this node is a good starting place for picking a weighted random number..
Take a look at that system line. It is about a million times safer (and easier on the eyes) than eval'ing a backtick command. With multi-arg system, you don't have to worry about quoting issues either.sub score { ## however you decide to assign a score to a filename } sub choose_weighted { ## from that other node } my @audio_files; find( sub { /\.(mp3|wav|wma)$/ && push @audio_files, $File::Find::name } +, 'C:\music' ); ## this could go inside the while loop if you needed to recalculate ## relative weights after every song is played: my @weights = map { score($_) } @audio_files; while (1) { my $index = choose_weighted(\@weights); system 'c:\Program Files\Windows Media Player\wmplayer.exe', $audio_files[$index]; print "Another? "; last unless <STDIN> =~ /^y/i }
Update: loaded @audio_files from File::Find
blokhead
In reply to Re: Opening random files (with bias) based on File::Stat information.
by blokhead
in thread Opening random files (with bias) based on File::Stat information.
by Cap'n Steve
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |