I don't know about access times in Windows -- you may have to keep track separately of when you've played the audio files if other things are interfering with the access times.

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..

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

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.