From owner-freebsd-questions@FreeBSD.ORG Sat May 5 19:17:39 2007 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id EAC1016A403 for ; Sat, 5 May 2007 19:17:39 +0000 (UTC) (envelope-from pigskin_referee@yahoo.com) Received: from web34410.mail.mud.yahoo.com (web34410.mail.mud.yahoo.com [66.163.178.159]) by mx1.freebsd.org (Postfix) with SMTP id B586013C455 for ; Sat, 5 May 2007 19:17:39 +0000 (UTC) (envelope-from pigskin_referee@yahoo.com) Received: (qmail 81088 invoked by uid 60001); 5 May 2007 19:17:39 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=dyc12QU3lnTIq+8bnsf5V8f/zRFYiFJcN00XdP/pxgTaGC8Np+ApQr5gDqm7LykOTNwtMJre7ri+FMmaco0F/JVh6Pwoc53nIDN/zv2g3oiPE4AX8/BxBJQGiZItoPOhvjPM1ksWwvOilRfSjcCyufFzwNZbSYh1sdPyRjBECkk=; X-YMail-OSG: C0tzpmEVM1niw0xOk4lAnY0MAp9HqRkgjRkHlWpDVoxARHe9ZyHrZE68kAXXNOp3GkWVVGC5T.61I2EQ59vdsgL8KVDr1Lf4MA5M3amAIU0jrwbXgJKCRg_jOMCicw-- Received: from [67.189.184.224] by web34410.mail.mud.yahoo.com via HTTP; Sat, 05 May 2007 12:17:39 PDT Date: Sat, 5 May 2007 12:17:39 -0700 (PDT) From: White Hat To: FreeBSD Users Questions MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <19743.80650.qm@web34410.mail.mud.yahoo.com> Subject: Perl Script in Apache X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 May 2007 19:17:40 -0000 I tried to get an answer to this on the Apache forum, but unfortunately, I was not successful. Running Apache on a FreeBSD-6.2 machine, I am attempting to set up a web page that changes a specific image on a daily basis. I found a Perl script that is supposed to do this, but it seems to fail. All that is displayed is a red [X]. If I run the script from the command line, it works, as it should. Well, at least it displays the correct file name. I assume I am doing something wrong with the actual web page, or else I am incorrectly calling the Perl script. This is a commented version of the script. ================================================= To display an image simply use this in your HTML: #!/usr/local/bin/perl # find out the day of the year my $day_of_year = (localtime(time()))[7]; # define the path where the images live "." is the current directory $path = "/usr/local/www/apache22/data/pics"; # read all the jpg, gif or png filenames from the directory into an array opendir(DIR, $path); @files = grep { /\.(jpg|gif|png)$/i } readdir(DIR); closedir(DIR); # sort the filenames alphabetically @files = sort( {lc $a cmp lc $b} @files); # count the number of images $no_of_images = scalar(@files); # Now the fun bit :) We loop through the images once before # repeating them in the same order. If we divide the current # number of day of the year by the number of images in the # directory we get the number of times have repeated the images. # We are interested in the remainder of this calculation (this # is calculated using the % operator). Note - there must be # less than 365 images in the directory! We need to subtract # one from this number because arrays start at zero not 1! if ( $no_of_images <= $day_of_year ) { $image_to_use = ($day_of_year % $no_of_images)-1; } else { $image_to_use = $day_of_year-1; }; print "Location: $files[$image_to_use]\n\n"; ================================================= -- White Hat pigskin_referee@yahoo.com ____________________________________________________________________________________ Looking for earth-friendly autos? Browse Top Cars by "Green Rating" at Yahoo! Autos' Green Center. http://autos.yahoo.com/green_center/