On Saturday, June 14, 2003, at 10:01 AM, deborah wrote:

In the same line as my last question.... once I tried to understand how Perl was interpreting string comparisons, I started experimenting with different strings.

What is Perl doing here? Why doesn't it use the "if" statement as a condition? It reassigns the variable value instead of using it as a conditional statement in the following code:

$password=bill;
if ($password = 'howard') {

= is Perl's assignment operator. This means set $password to 'howard'. I believe your were looking for == which is a logical comparison operator, but unfortunately, that still wouldn't do the trick. == is for comparing the equality of numbers, but you want to compare two strings. For that you need Perl's string comparison operator, eq. So to fix the line above try:


if ($password eq 'howard') {

Hope that helps.

James

        print "'$password' is a valid password.\n";
}else {
        print "'$password' is not valid.\n";
}

*******
This results in a printout that says: 'howard' is a valid password.

Thank you again,

Deborah


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to