use strict; use warnings;
You're comparing strings with the numerical comparison operator. Use eq instead of ==.
Well, you would be if you had actually populated your hash properly. You only assign one element to your hash, a reference to another anonymous hash. You need to assign a list of key-value pairs. Change = { } to = ( ).
Iterating through the entire hash defies the purpose of using a hash, especially when you know the key you want to locate.
Perl doesn't have a break keyword. C's break is called last in Perl.
Code that comes after a return doesn't get executed. That break is never reached.
use strict; use warnings; my %dbase = ( apple => "fruit", brinjal => "vegetable", coffee => "beverage", ); sub validate { my ($usr, $pwd) = @_; return exists($dbase{$usr}) && $dbase{$usr} eq $pwd; } my @info = ( "lemon", "juice" ); my $result = validate(@info) ? "ok" : "forbidden"; print "$result\n";
In reply to Re: sub always returns 1
by ikegami
in thread sub always returns 1
by blackgoat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |