selecting a random file

ronnie gauthier ronnieg
Mon May 17 11:48:43 PDT 2004


($OpenMe) = @_;
opendir(RUNNING,"$OpenMe")  || &return_error (31, "NewContestPath", $!);
   	  @RunningContests = readdir RUNNING;
	close(RUNNING);
	shift(@RunningContests); #drops .
	shift(@RunningContests); #drops ..

$n1 = int rand(@RunningContests); # random from total items in the array

print "$RunningContests[$n1]";


Here is the &return_error subroutine

sub return_error
{
local ($status, $keyword, $message) = @_;

print "Content-type: text/html", "\n\n";
print "<HTML>", "\n";
print "<HEAD>", "\n";
print "<TITLE>Unexpected Error, oh-oh</TITLE>","\n";
print "</HEAD><BODY>";
print "<p><p>= = = = = = = = = = = = =<BR>";
print "Status: $status <br>";
print "Keyword: $keyword<br>";
print "Message: $message<br>";
print "= = = = = = = = = = = = =<P>";
print "Please contact: ", "$webmaster";
print "</body></html>";

exit(0);
}



straight from one of my working scripts so it works. I just added the print to
show you the item of an array. HTH

On Sat, 28 Jun 2003 08:58:30 -0700 - "Net Llama!" <netllama at linux-sxs.org> wrote
the following
Re: selecting a random file

>I'm working on a blog (http://netllama.linux-sxs.org for the 
>curious/bored), and I'd like to add a feature that displays a random 
>image from a directory each time the page loads (or perhaps just via a 
>cronjob).  I'm sure that this is quite simple for someone with alot more 
>perl f00 than I.  anyone have any pointers?
>
>-- 
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>L. Friedman                       	       netllama at linux-sxs.org
>Linux Step-by-step & TyGeMo: 		    http://netllama.ipfox.com
>
>   8:55am  up 13 days, 13:37,  1 user,  load average: 0.07, 0.10, 0.10
>
>
>_______________________________________________
>Linux-users mailing list
>Linux-users at linux-sxs.org
>Unsubscribe/Suspend/Etc ->
>http://www.linux-sxs.org/mailman/listinfo/linux-users


More information about the Linux-users mailing list