CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...: Re: [l008com] Random Code Swapper...: Edit Log



Paul
Enthusiast

Aug 27, 2002, 4:29 AM


Views: 2785
Re: [l008com] Random Code Swapper...


Quote
•Take a predefined folder
•Choose a random item in that folder
•read the contents of that item, and spit it to the screen



Code
my $dir   = '/a/b/c'; 
my @files = ();

opendir DIR, $dir or die "Can't open dir $dir : $!";
@files = grep { !/^\./ } readdir(DIR);
closedir DIR;

open FILE, $files[rand @files] or die "Can't read file: $!";
read FILE, my $string, -s FILE;
close FILE;

print "Content-type: text/html\n\n";
print $string;



(This post was edited by RedRum on Aug 27, 2002, 4:31 AM)


Edit Log:
Post edited by Paul (Enthusiast) on Aug 27, 2002, 4:30 AM
Post edited by Paul (Enthusiast) on Aug 27, 2002, 4:30 AM
Post edited by Paul (Enthusiast) on Aug 27, 2002, 4:31 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives