Re: Random Imaging
by Zaxo (Archbishop) on Aug 01, 2003 at 14:14 UTC
|
I don't think your image file names are being taken as correct URLs. You've written them as relative host paths. Omitting the '.' may be enough.
Also, it wouldn't hurt to quote the attribute values in your tags. Try feeding your output to an html checker.
After Compline, Zaxo
| [reply] |
Re: Random Imaging
by Abigail-II (Bishop) on Aug 01, 2003 at 14:25 UTC
|
srand(time ^ $$);
Eeew! Where did you get this from? Many, many moons ago
I wrote a little CGI program that randomly returned an
image as well, and I discovered that it would often return
the same image twice in a row, if you have seed the random
generator with time ^ $$. I posted about this to
the newsgroup more than seven years ago.
http://groups.google.com/groups?selm=3148E9E1.21CA6C29%40www.iaf.nl&output=gplain
This resulted in the Camel II already warning against this
usage, and later versions of Perl using a much better default
salt.
Why, o, why, did you pick such a bad seed?
Abigail
| [reply] |
|
many moons ago I wrote a little CGI program ... with time ^ $$ ... I posted about this to the newsgroup more than seven years ago ... Why, o, why, did you pick such a bad seed?
Perhaps it is a comon mistake for new people to random numbers and perl? It sounds like you learned from your mistake 7 years ago. =)
-Waswas
| [reply] |
|
I was doing what was common practise back then. Since then
common practise has changed, and the documentation explicitely
warns against using time ^ $$. So, my question
remains, why did you choose time ^ $$?
Abigail
| [reply] |
Re: Random Imaging
by liz (Monsignor) on Aug 01, 2003 at 14:19 UTC
|
| [reply] |
Re: Random Imaging
by ChrisR (Hermit) on Aug 01, 2003 at 14:16 UTC
|
Without knowing the directory structure or file permissions you have setup, it is very hard to say what the problem is. However, there should be a fairly descriptive reason in your web logs. It looks to me like the paths for your image files may be incorrect. You might try changing ./pics/blink.gif to /pics/blink.gif and see if that helps but be sure to check your error log first. | [reply] |
|
In response to chrisR and zaxo, the whole ./ to just / makes no difference, I tried that a long time ago but thanks for the comments.
| [reply] |
|
At the URL you posted, the image links are now something like "../htdocs/img.jpg", which just won't work at all.
It still seems like "/pics/" is what the paths should start with. Even if you've already tried it, try changing the paths back to "/pics" again, so we can take a look at your running script that way and see what's going on.
| [reply] |
Re: Random Imaging
by Cine (Friar) on Aug 01, 2003 at 15:08 UTC
|
That is some ugly code. It generates incorrect HTML (it has so many errors, that you should read "HTML for dummies" again), not that my fix will go through a validator...
The code is completly unmaintainable and gives the impression that you have absolutely no idea of what you are doing.
#!c:\perl\bin\perl.exe -w
use strict;
my @imgArray = (
{
file => "./pics/blink.gif",
h => 320,
w => 240,
title => "Blink 128 (1)",
},
{
file => "./pics/sum41.gif",
h => 316,
w => 500,
title => "Sum 41",
},
#and so on
...
);
#dont use srand, unless you want a PREDICTABLE series of numbers every
+ time!
my $num = rand(@imgArray);
my $img = $imgArray[$num];
print "Content-type: text/html\n\n";
print <<HTML;
<html>
<head>
<title></title>
</head>
<body bgcolor=lightgrey>
Index: $num <br>Image: $$img{file}
<br>
<br>
<center>Random imaging with Perl.....</center>
<br>
<br>
<center>
<img src="$$img{file}" border=1 height="$$img{h}" width="$$img{w}">
<br>
<br>
<font>$$img{title}</font>
</center>
</body>
</html>
HTML
T
I
M
T
O
W
T
D
I | [reply] [d/l] |
|
I think that Cine could be making a good point here; that it is important to seperate the programatic logic from the HTML presentation, even in a small script. His example code does a good job of that. For this reason I would mod parent up ++.
However, the tone of the his message is a bit off-putting. For this reason I would mod parent down --.
-------------------------------------
Nothing is too wonderful to be true
-- Michael Faraday
| [reply] |
|
I've only been a member here for like 5 hrs, is mod parent up ++ and mod parent down -- some type of rating thing on here?
| [reply] |
|
|
I don't understand how I'm generating all this horrible html code, when the only problem I seem to have is that the picture is not displayed. If you want to see what comes up go here: http://165.190.25.157/cgi-bin/image.pl
| [reply] |
|
The problem is that you are populating your IMG tags with this path:
/htdocs/pics/{random image file}
However, your pics are here:
http://{your site IP}/pics/{random image file}
Without knowing your filesystem, it's hard to say exactly where, but somewhere you are introducing "/htdocs/" to the path. My guess is the "./" part of the path, but you've said changing that has no effect.
Off the top of my head: could this be a config issue with your server? Perhaps you are pointing at the directory above your docroot (ie htdocs) instead of the htdocs directory?
AH
Update: I copy/pasted your code and ran it on my machine. When I removed the "." before the "./pics" it worked. If you do that and you are still getting "/htdocs/pics" I'd say it's almost certainly a config issue.
| [reply] |
|
|
|
I don't understand how I'm generating all this horrible html code
No that is obvious.
when the only problem I seem to have is that the picture is not displayed
Looks can be deceiving.
But your problem is obvious, you dont have a directory called /pics on your webserver, yet that is the link you send to the browser! It does seem you have a /cgi-bin/pics/ but that tries to execute the image as a cgi-script, which does not go well.
T
I
M
T
O
W
T
D
I
| [reply] [d/l] |
|
|
|
|
When you use $$img{...}, what does using two $'s mean...does that signify that you are using an array of hashes rather than just a simple array where you would use only one $ to call a particular value?
Thanks
| [reply] |
|
When you use $$img{...}, what does using two $'s mean...does that signify that you are using an array of hashes rather than just a simple array
Yes and no. An array of hashes are really an array of references to hashes. Therefore when you fetch something from the array, you get a hash reference back.
To actually use the hash, you then have to de-reference it. There are two syntactic ways of doing that $reference->{} or $$reference{}
I like the latter best, mostly because its shorter and because it is coloured yellow in emacs...
Read the perlref manpage
T
I
M
T
O
W
T
D
I
| [reply] [d/l] |