At 8:28 PM -0400 10/26/02, Mark Knipfer wrote:
On 10/26/02 1:25 PM, Trey Harris wrote:
Did you test this code snippet it? It won't work. You can't use a numeric comparison to test for stringwise equality. (Sorry to be nitpicky, but it matters here.)
No problem.  After I pasted the Perl code in my message, it was Perl
code that I copied to the clipboard and did not copy the latest code
revision I was working on that time.

I don't mind nitpicky, because errors do not run/work in Perl.
Actually, if you run without warnings, that code snippet would appear to work.

#!/usr/bin/perl

$login = 0;
print $login == "root" ? 'root it is' : 'root is it?';
__END__
#root it is

compare to:

#!/usr/bin/perl -w

$login = 0;
print $login == "root" ? 'root it is' : 'root is it?';
__END__
#File "eq_test.pl"; Line 4: Argument "root" isn't numeric in numeric eq (==)

If forced to treat a string as a number, Perl gives it the value 0. Use 'eq' for string comparisons.

(Maybe you knew all this, but it wasn't clear from the comment above :-)

HTH

1;
--

- Bruce

__bruce_van_allen__santa_cruz_ca__

Reply via email to