Click to See Complete Forum and Search --> : Hekp with PERL
HuggyBear
11-27-2001, 01:13 PM
Why does this not work properly???
my ($add_create,$create_sw,$add_sw);
$add_create='def';
if ($add_create=='abc'){
$create_sw=1;
print "\$create_sw=$create_sw\n";
}elsif ($add_create=='def'){
$add_sw=1;
print "\$add_sw=$add_sw\n";
}
NEVER MIND I'M A FREAKING MORON!
eq
[ 27 November 2001: Message edited by: HuggyBear ]
TheLinuxDuck
11-27-2001, 01:18 PM
When doing string comparisons, you have to use <STRONG>eq</STRONG>, instead of == (which is for numeric comparison).
Try
if($var eq "this")
instead. (^=
You can also use <STRONG>ne</STRONG> instead of !=.
vinman
11-27-2001, 03:22 PM
Originally posted by HuggyBear:
<STRONG>Why does this not work properly???
my ($add_create,$create_sw,$add_sw);
$add_create='def';
if ($add_create=='abc'){
$create_sw=1;
print "\$create_sw=$create_sw\n";
}elsif ($add_create=='def'){
$add_sw=1;
print "\$add_sw=$add_sw\n";
}
NEVER MIND I'M A FREAKING MORON!
eq
[ 27 November 2001: Message edited by: HuggyBear ]</STRONG>
Not sure what context this code is to be used for but in "if" block B you have: print "\$add_sw=$add_sw\n";
$add_sw has already been defined in the line above the print statement so I don't believe $add_sw needs to be redefined in the print. I think all you need is:
print $add_sw . "\n";
If someone reading this knows better, please set me strait. That's my two cents.
TheLinuxDuck
11-27-2001, 03:55 PM
Originally posted by vinman:
<STRONG>Not sure what context this code is to be used for but in "if" block B you have: print "\$add_sw=$add_sw\n";
$add_sw has already been defined in the line above the print statement so I don't believe $add_sw needs to be redefined in the print. I think all you need is:
print $add_sw . "\n";
</STRONG>
The print statement in question is not making any kind of assignment, but simply designed to show the name of the variable. Take a closer look at the print statement:
print "\$add_sw=$add_sw\n";
Notice the preceding (\)forwardslash. That escapes the ($) dollar sign so that it is printed as a mere dollar sign. This allows the coder to print out things that require the $ to be printed, and to not interpolate (or convert a variable name into it's value) when used in double quotes.
That way, when the code gets run, it prints
$add_sw=1
Mostly for debugging purposes. (^=