Gossamer Forum
Home : General : Perl Programming :

Rotating Images in ASP File: Links and No Links

Quote Reply
Rotating Images in ASP File: Links and No Links
Hi there.

I have an .asp scripted in Perl, which has a delimited array that includes the following variables: (Image Location, Text, and URL).

Some of the records do not have URLs. I have the rotating script working just fine, with the exception of NOT printing URLs if there are no URLS.

BTW: This is a Perl question even though it deals with an .asp file that I am including in another .asp file. Smile I have posted this question on three ASP Messageboards with no response, so I thought I would try my luck here. Smile

Here is what I have:

Code:
<%@language=perlscript%>
<%
# The array Image holds banner-names and it's associated text.
# Put your images and associated links in the array.
my @Image = (
"http://www.coco.cc.az.us/images/rotate/1.jpg | Teaching Art at CCC. | http://www.coco.cc.az.us/collegecatalog/cat99/courses/CrsART.htm",
"http://www.coco.cc.az.us/images/rotate/2.jpg | Computer Information Systems at CCC. | http://www.coco.cc.az.us/collegecatalog/cat99/programs/CertComp.htm",
"http://www.coco.cc.az.us/images/rotate/3.jpg | Students at CCC. | http://www.coco.cc.az.us/student_services/",
"http://www.coco.cc.az.us/images/rotate/4.jpg | CCC Computer Lab at Flagstaff Campus. | http://www.coco.cc.az.us/~complab/",
"http://www.coco.cc.az.us/images/rotate/5.jpg | Fire Science at CCC. | http://www.coco.cc.az.us/collegecatalog/cat99/programs/CertFire.htm",
"http://www.coco.cc.az.us/images/rotate/6.jpg | Studying Hard is the key to success. | http://www.coco.cc.az.us/~lec/",
"http://www.coco.cc.az.us/images/rotate/7.jpg | Page Campus. | http://www.coco.cc.az.us/~page/",
"http://www.coco.cc.az.us/images/rotate/8.jpg | San Francisco Peaks in Flagstaff, AZ. | http://www.azsnowbowl.com/",
"http://www.coco.cc.az.us/images/rotate/9.jpg | Science at CCC. | http://www.coco.cc.az.us/~science/",
"http://www.coco.cc.az.us/images/rotate/11.jpg | Welcome to CCC. | http://www.coco.cc.az.us/misc/about.html",
"http://www.coco.cc.az.us/images/rotate/12.jpg | CCC - A place of learning. | ",
"http://www.coco.cc.az.us/images/rotate/13.jpg | Welcome to CCC. | http://www.coco.cc.az.us/misc/about.html",
"http://www.coco.cc.az.us/images/rotate/14.jpg | 1999 Spring Commencements. | http://www.coco.cc.az.us/misc/about.html",
"http://www.coco.cc.az.us/images/rotate/16.jpg | Hands-on Learning is the key to success. | http://www.coco.cc.az.us/misc/about.html",
"http://www.coco.cc.az.us/images/rotate/17.jpg | CCC Band. | ",
"http://www.coco.cc.az.us/images/rotate/18.jpg | CCC- Learning that Works. | http://www.coco.cc.az.us/collegecatalog/"
);

# The call int(rand 5) randomizes a value between 0 and 4 and performs a cast-conversion
# of the number to make it an integer. Then it splits the given array element by the
# pipe-symbol.
my ($img, $text, $url) = split(/\|/, $Image[int(rand 16)]);

if ($Image == $url) {
$output .= "<a href=\"$url\"><img SRC=\"$img\" alt=\"Rotating Image\" border=\"0\"></a>";
$output .= " </td></tr><tr><td valign=\"top\"><div align=\"center\">";
$output .= "<center><table border=\"1\" width=\"80%\" cellpadding=\"2\" cellspacing=\"0\">";
$output .= "<tr><td bgcolor=\"EEEEEE\"><font face=\"Verdana\" size=\"1\"><b>Photo Caption:</b>";
$output .= " <a href=\"$url\">$text</a></font></td>";
$output .= "</tr></table></center></div></td></tr>";
}
else {
$output .="<img SRC=\"$img\" alt=\"Rotating Image\" border=\"0\">";
$output .= " </td></tr><td valign=\"top\"><div align=\"center\">";
$output .= "<center><table border=\"1\" width=\"80%\" cellpadding=\"2\" cellspacing=\"0\">";
$output .= "<tr><td bgcolor=\"EEEEEE\"><font face=\"Verdana\" size=\"1\"><b>Photo Caption:</b>";
$output .= " $text</font></td>";
$output .= "</tr></table></center></div></td></tr>";
}
$output .="</table></center></div>";
%>
<div align="center"><center>

<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><p align="center">
<font face="Arial" size="2" color="00009c">
<%=$Week_Days[$Week_Day]%>, <%=$Months[$Month]%> <%=$Month_Day%>,<%=$Year%>
</font><br>
<%=$output%>
</body>
</html>

Note: Disregard the time and date tags. They are functioning fine. I have only included the second Perl script for the Rotating Image.

I know that the problem is with the following line:

Code:
if ($Image == $url) {

I tried other statements, including:

Code:
if ($Image eq $url) {

AND

Code:
if ($Image) && ($url) {

None of this work. Frown

Basically, I am trying to find a way to state that if the record line includes a URL, then print the URL, if not, then only print the image and text.

Does this make sense?

If so, any suggestions are greatly appreciated.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited August 09, 1999).]
Quote Reply
Re: Rotating Images in ASP File: Links and No Links In reply to
Try this:
Code:
if ("$Image" eq "$url") {
instead of this:
Code:
if ($Image eq $url) {


Regards,

Pasha

------------------
The Flying Cranes, Inc:
http://www.theflyingcranes.com
Perl scripts & Web promotion:
http://find.virtualave.net
Quote Reply
Re: Rotating Images in ASP File: Links and No Links In reply to
Pasha,

Thanks for the suggestion. It did not work. When I changed the codes to what you suggested, None of the links showed up.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Rotating Images in ASP File: Links and No Links In reply to
Hey,

Try:

if ($Image eq /$url/) {

This should look for $url IN $Image. The other's try to match $Image and $url.
Hope that works...


------------------
WFMY-TV Webmaster

[This message has been edited by Chris071371 (edited August 10, 1999).]
Quote Reply
Re: Rotating Images in ASP File: Links and No Links In reply to
If that doesn't work, try:

if ($Image =~ /$url/) {

------------------
WFMY-TV Webmaster
Quote Reply
Re: Rotating Images in ASP File: Links and No Links In reply to
What is:

if ($Image == $url) {

Trying to test for... I have seen a bunch of tests, but not sure what the point is.

if ($Image =~ /$url/)

This will test for the contents of the &url variable in $Image. If it finds it, at least once, the 'if' test will be set to true. To test if $Image contains only $url , you can do something like:

if ($Image =~ /^$url$/i)

It would do the same 'test' as $Image eq $url , ignoring case.

It might be that case is your problem, since /path/to/the/file is not the same as /path/to /the/File

Just some other ideas.

Quote Reply
Re: Rotating Images in ASP File: Links and No Links In reply to
Chris071371,

Thank you...That was the right answer I was looking for! The first suggestion worked:

Code:
if ($Image eq /$url/) {

Thanks, pugdog for your contributions.

If anyone is interested in seeing how this script turned out, go to:

www.coco.cc.az.us/_private/newdefault.asp

Thanks.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited August 10, 1999).]

[This message has been edited by Eliot (edited August 10, 1999).]

[This message has been edited by Eliot (edited August 10, 1999).]