SPUG: Another program head scratcher

EXT-Corcoran, David david.corcoran at Boeing.COM
Sat Jul 13 12:28:38 CDT 2002


Off the top, I think you need to use the eq operator rather than == in line
15.

-----Original Message-----
From: Sweethomes [mailto:sweetsue at sweethomes.com]
Sent: Saturday, July 13, 2002 10:25 AM
To: Seattle Perl User's Group
Subject: SPUG: Another program head scratcher


If you guys are sick of me, let me know LOL (I've been learning a lot the
past week or so, PHP and MySQL are more my forte, thank you for your help
lately!).  I have a program (see near bottom) that is supposed to open a
file, read it, check to see if an ip is already entered or if the count has
reached 2 and if so, print out a quick message saying they can't enter as
they already have.  Then, if it's a new ip and the count is less than 2, it
will record the ip address, increment the count then (and this isn't in
there yet) proceed to the "contest" page.  It's only doing the count to 1
over and over and it's not picking up that an ip has been there before.
Here are the errors I see when trying to process it:
 
Use of uninitialized value in numeric eq (==) at test2.cgi line 15.
Argument "67.40.29.147" isn't numeric in numeric eq (==) at test2.cgi line
15.
Argument "0|\n" isn't numeric in numeric eq (==) at test2.cgi line 15.
Use of uninitialized value in string ne at test2.cgi line 75, <RDIR> line 1.

And here is what the ipdata.txt file records (not actual ip address
obviously - and the 0| line was manually put in place to allow incrementing
from 0):
 


0| 

1|12.12.12.12 

1|12.12.12.12 

1|12.12.12.12

Here is the program:
 


#!/usr/bin/perl -w 

require('vars.pl'); 

$TheWhere = $ENV{REMOTE_ADDR}; 

open (RDIR, "$datafile") || die "Can't open '$datafile' $!\n"; 

@ipx=<RDIR>; 

close (RDIR); 

foreach $line(@ipx) { 

@ipstuff = split(/.\\n/, $line); 

foreach $ipl (@ipstuff) { 

($cnt, $ipadd) = split(/.\|./, $ipl); 

if ($TheWhere == $ipadd) { 

$BODY .= qq~ <font size=2 face="Verdana,Arial,Helvetica">You have already
been to this page - you cannot win again.</font><p>~; 

$BODY .= qq~<p><center><a href=http://www.somedomain.com>Back to main
page</center> 

~; 

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

print <<ERRORHTML; 

<html> 

<head> 

<title>You've won already</title> 

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 

</head> 

<body bgcolor="#FFFFFF" text="#000000"> 

<br><br><br><br> 

<table width="600" border="0" cellspacing="1" cellpadding="4"
bgcolor="#333333" align="center"> 

<tr> 

<td bgcolor="#EEEEEE"><font color="#FF0000" size="2" face="Arial, Helvetica,
sans-serif"><b>Here is the problem:</b></font></td> 

</tr> 

<tr> 

<td bgcolor="#EEEEEE">$BODY</td> 

</tr> 

</table> 

</body> 

</html> 

ERRORHTML 

exit; 

} 

elsif ($cnt == 2) { 

$BODY .= qq~ <font size=2 face="Verdana,Arial,Helvetica">This prize has been
won the maximum number of times.</font><p>~; 

$BODY .= qq~<p><center><a href=http://www.somedomain.com>Back to main
page</center> 

~; 

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

print <<ERRORHTML; 

<html> 

<head> 

<title>Max Winners</title> 

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 

</head> 

<body bgcolor="#FFFFFF" text="#000000"> 

<br><br><br><br> 

<table width="600" border="0" cellspacing="1" cellpadding="4"
bgcolor="#333333" align="center"> 

<tr> 

<td bgcolor="#EEEEEE"><font color="#FF0000" size="2" face="Arial, Helvetica,
sans-serif"><b>Here is the problem:</b></font></td> 

</tr> 

<tr> 

<td bgcolor="#EEEEEE">$BODY</td> 

</tr> 

</table> 

</body> 

</html> 

ERRORHTML 

exit; 

} 

else { 

open(RDIR, "$datafile"); 

@ipx = reverse(split (/.\|\\n/, <RDIR>)); 

if ($ipx[1] ne $TheWhere) { 

$cnt = $ipx[0]; 

$cnt++; 

} else { 

$cnt = 1; 

} 

close(RDIR); 

open(INF,">>$datafile"); 

print INF "$cnt|$TheWhere\n"; 

close(INF); 

} 

} 

}


www.web-dev-design.com <http://www.web-dev-design.com/>
<http://www.web-dev-design.com/>  <http://www.enso-company.com/>
<http://www.web-dev-design.com/> 
------------------------------------
Susanne Bullo, Developer     Web Dev Design


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/archives/spug-list/attachments/20020713/1413b0c3/attachment.htm


More information about the spug-list mailing list