#!/usr/local/bin/perl # # rotater.pl # version 961119 # copyright 1996 by bo larsson # all rights reserved # # this CGI program returns one file name from the specified directory every time # it is called. Once the file name has been returned, it is not used again until # all file names in the directory have been displayed. # # bugs or feedback to bliss@seagull.net # for information on how to use, visit http://www.seagull.net/bliss/ # make sure your $file_list directory is world-writeable (chmod 777) so the # last_file file can be created and written to. $file_list = "/home/bliss/web/graphics"; $last_file = "last.txt"; # get the name of the last graphic displayed open(LAST_FILE,"$file_list/$last_file"); $last = ; close(LAST_FILE); # get contents of graphics directory opendir(FILE_LIST,"$file_list"); @the_files = readdir(FILE_LIST); closedir(FILE_LIST); # strip out unwanted file names and store results in $the_list $count = 0; foreach $one (@the_files) { if (($one ne ".") && ($one ne "..") && ($one ne "$last_file")) { $count++; $the_list[$count] = $one; } } # now, what was the last read file name? $count = 0; foreach $one (@the_list) { $count++; if ($one eq $last) { $target = $count; } } if ($target > $#the_list) { $target = 1; } # print and save the file name print "Content-type: text/plain\n\n"; open(LAST_FILE,">$file_list/$last_file"); flock(LAST_FILE,2); print LAST_FILE "@the_list[$target]"; print "@the_list[$target]\n"; flock(LAST_FILE,8); close(LAST_FILE);