Gossamer Forum
Home : General : Perl Programming :

Using 0 (zero) as a Value?

Quote Reply
Using 0 (zero) as a Value?
I set up a configuration file (example)

#do something
#(1=yes do something, 0=no don't)
#---------------------------------------
$varSomething = "0";


if ($varSomething) {big fun}
else {no fun at all}

Now, when I run this script it gives an error when the value is set to "0".

"...file did not return a true value at line blah"

Of course, I thought that was the whole point of 1 or 0. Any pointers?

In the mean time I simply changed the instructions to use 1=yes and 2=no and then used
if ($varSomething == "1") { } else { }

Any help is much appreciated...

Also, how do I do a "timer" for input? I have $inPut = <STDIN>; (and then what to do if yes or no, etc) but I'd like someway to kill the program if no input for 60 seconds or so.
Quote Reply
Re: [Watts] Using 0 (zero) as a Value? In reply to
This should work;

Code:
#!/usr/bin/perl

use CGI;
my $IN = new CGI;

print $IN->header();

my $var = 1;

if ($var) {
print "First one was true...<BR>";
} else {
print "First one was false...<BR>";
}

my $var2 = 0;

if ($var2) {
print "Second one was true...<BR>";
} else {
print "Second one was false...<BR>";
}

my $var3 = "0";

if ($var3) {
print "Third one was true...<BR>";
} else {
print "Third one was false...<BR>";
}

Untested, but that should give;

Quote:
First one was true...
Second one was false...
Third one was false...

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!