SPUG: Another program head scratcher

Creede Lambard creede at penguinsinthenight.com
Sat Jul 13 12:51:33 CDT 2002

On Sat, 2002-07-13 at 10:25, Sweethomes wrote:
> 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 "" 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.

OK, I'll admit I didn't get any farther than this, because the "isn't
numeric" is a CLUE in capital letters. :)

When you're dealing with numbers, you use "==". When you're dealing with
strings, you use "eq". Unless, of course, you decide to use =~ instead.
If I remember right =~ is more expensive than eq, but also more flexible
because of the regular expressions (as long as you don't let the
"explosion in a punctuation factory" stuff scare you, of course). Just
to use a trivial example, you can replace

if (uc(substr($answer, 0, 1)) eq 'Y') { return 1; }


if ($answer =~ /^y/i) { return 1; }

 * .~. `( 
` / V \  . Creede Lambard                : Just who is this General
 /(   )\   creede at penguinsinthenight.com :   and why is he reading my

Perl Programmer and Linux Sysadmin, reasonable rates. Inquire within.
GPG key at http://www.penguinsinthenight.com/creede_public_key.asc

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: This is a digitally signed message part
Url : http://mail.pm.org/archives/spug-list/attachments/20020713/cb5036c0/attachment.bin

More information about the spug-list mailing list