Hi,
Just found another one of them annoying bugs today - exemplified by the code
below. It's easy to see a non existent username will match an empty password
(silent conversion between undef and empty string).
Javascript has an explicit equality operator that does not coerce types
(called the ===). In perl, I usually check for undefs (until I forget). Is
there such an operator for perl ?

__DATA__

use strict;
use warnings;

my %users = (
    root   => 'admin',
    guest => 'anonymous',
);

chomp(my $username = <>);
chomp(my $password = <>);

if ( $users{$username} eq $password ) {
    print "Welcome :)\n";
} else {
    print "Go Away !\n";
}
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to