string comparison - exact matching... 
Author Message
 string comparison - exact matching...

in the following statement:

if (X eq Y)
   {
   allowed
   }
else
  {
   disallow
  }

How would you get it to return true ONLY if the two strings (x and y) are
exactly the same. The way it is now doesn't work - if x is "waf" and y is
"w", right now it is evaluating as true. Any ideas? (for passwords)

Thanks,
Forest Johns



Sat, 17 Nov 2001 03:00:00 GMT  
 string comparison - exact matching...
: in the following statement:

: if (X eq Y)

   if ($X eq $Y)

:    {
:    allowed
:    }
: else
:   {
:    disallow
:   }

: How would you get it to return true ONLY if the two strings (x and y) are
: exactly the same.

   Pretty much the way you have it there (except it doesn't "return
   anything, and it is not even Perl code...)

: The way it is now doesn't work - if x is "waf" and y is
: "w", right now it is evaluating as true.

   I do not believe you (ignoring the fact that you are now talking
   about yet more variables. This is the first place that x and y
   are mentioned. X and Y are not the same as x and y).

   Prove it with Perl code that does what you says it will do.

: Any ideas?

   One idea would be to post Perl code to the Perl newsgroup that
   exhibits the behavior that you want to discuss.

: (for passwords)

   I don't know what that might mean, but there are 4 Frequently
   Asked Questions that have "password" in them. Maybe they will
   help with whatever it is that you are wanting.

------------------------
#!/usr/bin/perl -w
use strict;

my $x = 'waf';
my $y = 'w';

if ( $x eq $y )
   { print "true\n" }
else
   { print "false\n" }
------------------------

output:

false

   See? Barely more characters than you were already typing, but
   it is Perl code not pseudo-code.

--
    Tad McClellan                          SGML Consulting

    Fort Worth, Texas



Sat, 17 Nov 2001 03:00:00 GMT  
 string comparison - exact matching...

Quote:

>in the following statement:

>if (X eq Y)
>   {
>   allowed
>   }
>else
>  {
>   disallow
>  }

>How would you get it to return true ONLY if the two strings (x and y) are
>exactly the same. The way it is now doesn't work - if x is "waf" and y is
>"w", right now it is evaluating as true. Any ideas? (for passwords)

>Thanks,
>Forest Johns


#!/usr/bin/perl -w

$x = "waf";
$y = "w";

if ($x eq $y) {
   print "good";

Quote:
} else {
   print "bad";
}

output:  bad

It works for me.

Lauren



Sat, 17 Nov 2001 03:00:00 GMT  
 string comparison - exact matching...

Quote:

>in the following statement:

>if (X eq Y)
>   {
>   allowed
>   }
>else
>  {
>   disallow
>  }

>How would you get it to return true ONLY if the two strings (x and y) are
>exactly the same. The way it is now doesn't work - if x is "waf" and y is
>"w", right now it is evaluating as true. Any ideas? (for passwords)

No it doesn't...

if ("waf" eq "w")
   {
   print "allowed\n";
   }
else
  {
   print "disallowed\n";
  }

Gives the output : disallowed

--
Sam

Every human culture has good and bad points. Every computer program has
Eveone more bug. Even Perl.
        --Larry Wall



Sun, 18 Nov 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Exact string matches

2. How to do an exact comparison?

3. Fuzzy match string comparison routines

4. Regexp (exact match wanted)

5. Exact match

6. GD module question: not matching exact colors (DigitalColor Monitor)

7. question about exact match

8. Exact match with the Regular expression

9. match exact n times?

10. Exact match, but Insensitive

11. trying to use grep to give an exact match

12. exact match

 

 
Powered by phpBB® Forum Software