Web Hosting Talk







View Full Version : Scripting question (PERL)


hypernatic.net
03-28-2002, 04:39 PM
For some reason it is not working... Could anyone check what I am doing wrong?

What I want is it to check if var $A is undefined (so left BLANK on the form) and if so set another variable to something else...

if ($A = '') {$B = '30'};
(note that $A = '' are actually ' ' (shows like a double quote, but it actually is two single quotes)
Could anyone tell me what I am doing wrong?

Thanks guys!!

taz0
03-28-2002, 04:49 PM
try this:
if (!$A)
{
$B=30;
}

hypernatic.net
03-28-2002, 05:04 PM
Damn forgot! :P

Thanks!! Works like a charm :)

Tim Greer
03-28-2002, 07:48 PM
That won't work, if you want to asign 0 to $A. The reason why your original example didn't work, is because you were assigning the variable the value, not checking it. Refer to the difference between = (assigning) and == (checking).

cgiGeek
03-28-2002, 09:02 PM
my $A='';# douuble '
my $B='';# double '

$B="What ever" unless($A);

YUPAPA
03-28-2002, 10:31 PM
IS THIS!!!!!!!!!!


#!/usr/bin/perl
use strict;
my $a;
my $b;

if($a == "") { $b = "30"; }



if you are dealing with numbers, then use "==" when you are comparing. Otherwise use "eq" if you are comparing string
SO... for string...



if($a eq "") { $b = "thirty"; }



UNDERSTAND?
:)

taz0
03-28-2002, 10:56 PM
Remember Larry Wall's motto: There's more than one way to do it.