Forum Moderators: coopster & phranque

Message Too Old, No Replies

My script won't compare against a string

Please Help!

         

adni18

8:44 pm on Oct 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



uugh! Here's my script. Its supposed to print the image script if the day is 10/20.

---------------

#!/usr/bin/perl

use CGI;

if(&date eq '2004')
{
print "<img src=\"graphics/holiday-welcomes/Welcome_fourth.jpg\" alt=\"IronMagma is Celebrating the Fourth of July!\">";
}

else
{

@images=('welcome_dust.gif','Welcome_.gif','rwlogo.gif','linux.gif');
@alt=('Dust','Linux RedHat','RealityWebs','Linux');
@links=('galleries/f/v/dust.shtml','121x45','195x88','182x78');

srand; $num=int(rand(scalar(@images))); print "Content-Type: text/html\n\n<a href=\"../$links[$num]\"><img src=\"graphics/$images[$num]\" border=0 alt=\"$alt[$num]\" width=300 height=300></a>";
}
print "-";
print &date;
print "-";

sub year {
@dates=localtime();
$dates[5]+=1900;
$dates[4]++;
$final=sprintf("%0.2d", $dates[5]);
return $final;
}

sub date {
@date=localtime();
$date[4]++;
$fina=sprintf("%0.2d", $date[4])."/".sprintf("%0.2d", $date[3]);
return $fina;
}

[edited by: jatar_k at 6:21 pm (utc) on Oct. 21, 2004]
[edit reason] removed urls [/edit]

MichaelBluejay

3:11 am on Oct 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well, you haven't said what actually does happen or what kind of debugging you tried.

How about putting this after your use CGI line:

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

$test = &date;
print "-- $test --";
exit;

Incidentally, I don't see your print header command (e.g., the Content-type line).

adni18

11:56 am on Oct 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The reason I don't have a Content-type header is this acts as a server-side include, and whenever I try

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

, it appears on the page as Content-type:text/html
\n
\n.

Whenever I run this script, it just runs the defined else{. it doesn't run the if( statement because for some reason, it simply won't compare the two strings.

volatilegx

2:55 pm on Oct 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is comparing the strings... they just don't match. Try printing the results of &date instead of doing the if statement. I'll bet the results just aren't what you are expecting.

adni18

3:57 am on Oct 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nevermind guys, i figured out what was wrong. My server had a slight incompatibility error with my script, but it's fixed. Thanks anyway!