Forum Moderators: coopster & phranque

Message Too Old, No Replies

Trouble w/Random Image (Perl)

See description below.

         

jarett

8:51 pm on Jun 14, 2003 (gmt 0)

10+ Year Member



Hi all,

I found some code on this forum regarding a random image script.

Here is the code:
#! /usr/local/bin/perl

$basedir = "http://www.mydomain.net/images/";

@files = qw(1.bmp 2.bmp 3.bmp);

srand(time ^ $$);
$num = rand(@files);

print "Location: $basedir$files[$num]\n\n";

Here is the error:
failed to open log file
fopen: Permission denied
[Sat Jun 14 16:47:01 2003] [error] [client 142.161.128.92] Premature end of script headers: /usr/local/plesk/apache/vhosts/domain.net/cgi-bin/rand_image.pl

I'd really appreciate any help you all can offer on this. I've been looking for a script to display a random image for quite a while, and haven't found one that worked for me. I'd love to get this one going.

Thanks in advance!
Jarett

[edited by: jarett at 8:54 pm (utc) on June 14, 2003]

DrDoc

12:35 am on Jun 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World!

Shouldn't this line:
@files = qw(1.bmp 2.bmp 3.bmp);
be this instead:
@files = array("1.bmp","2.bmp","3.bmp");

Why that would give you a "log file error" I have no clue...

jarett

7:29 am on Jun 15, 2003 (gmt 0)

10+ Year Member



DrDoc: Thank-you for your suggestion. Unfortunately, making that change resulted in the exact same error(s). Nonetheless, appreciate the shot.

BCMG_Scott

2:38 pm on Jun 16, 2003 (gmt 0)

10+ Year Member



First:

@files = qw(1.bmp 2.bmp 3.bmp);
@files = array("1.bmp","2.bmp","3.bmp");

are identical. qw is a special that tells perl to QuoteWord. The parenthesis assume an array list. Thus you can do this:

($var1,$var2,$var3) = split(@array);

A LIST is contained in ( ) and an array is a LIST.

Second: I copied your code directly and ran it on the command line and it worked. One thing to check, where is perl located on your system? On mine it is /usr/bin/perl, so I made that change at the top after the shebang.

Scott Geiger