Wednesday, February 21, 2007

How not to check if a hash key exists in Perl

Just had a job candidate in here. This is how she checked if a hash key existed:


foreach my $val (sort keys %foo) {
if ($val eq $searchstring) {
print "Found!\n";
}
}


We decided not to hire her.