K Clark wrote:
> 
> linux environment. have o'reilly cookbook & learning perl (2nd ed.).
> 
> desire to randomly choose a filename of mp3 files in a directory
> containing only mp3's.
> 
> then, write the name of this filename to a file that has
> "http://myurl.org/mywebpath/..."; inserted before the filename so that i
> end up with a file that can be inserted into an email (or mailed
> straightaway to a list).
> 
> i am confused about alot, but first, do i need to read the directory
> filenames into a list, and then randomly choose one, or is their a
> function which will do so?
> 
> if such a function does exist and is inside one of the books mentioned,
> merely pointing me in the right direction would be very helpful. i do
> want to figure this out.


If you want to choose a random file name from a directory then you can
modify the answer in perlfaq5 "How do I select a random line from a
file?":

#!/usr/bin/perl -w
use strict;

my $dir = '/www/mp3';
opendir DIR, $dir or die "Cannot open $dir: $!";

my $count;
rand(++$count) < 1 && ($file = $_) while defined( $_ = readdir DIR );

print "http://www.quantifier.org/mp3/$file";;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to