Hi,
Obviously I do use the explicit notation, until that one time that I forget
... For this program, the right solution includes yours *and* the extra
check on the dictionary.
Being more specific, these perl lines:

die if ! exists $users{$username};  <---- I'd like to get rid of this line
if ( $users{$username} eq $password ) {
 ...
}

are pretty much this JS:

if (users[username] === password) {
}

The thing is, in JS I'm not afraid an underfined will turn out equal to the
empty string. (Well, I actually would fear it, if it wasn't for the
wonderful triple-equal operator).


On 13 May 2011 00:48, sawyer x <[email protected]> wrote:

>
> On Thu, May 12, 2011 at 11:53 PM, ynon perek <[email protected]> wrote:
>
>> 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 ?
>>
>
> You can (and should) use more explicit notation:
>
>
> chomp( my $username = <> );
> chomp( my $password = <> );
>
> defined $username && defined $password
>     or die "Missing username and password";
>
> In a correct interface (if you're using web, this would be done in JS in
> the front, *and* in the back) you should be checking your input to make sure
> it was inserted correctly.
>
>
> _______________________________________________
> Perl mailing list
> [email protected]
> http://mail.perl.org.il/mailman/listinfo/perl
>
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to