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