=begin perlmonkcomment
####
=cut
$::WORKAROUND = 0;
sub find_in {
my ($data_ref, $string) = @_;
my $result = 'no result';
# reset the iterator for %$data_ref:
keys %$data_ref if ($::WORKAROUND);
while ( my ($name , $value) = each %$data_ref) {
if (lc($name) eq lc($string)) {
$result = $value;
last;
}
}
return $result;
}
sub look_for_data {
my %hash = ( A => 'xxx' , B => 'xxx' , C => 'xxx' , D => 'xxx');
print "D: " . find_in(\%hash , 'D') . "\n";
print "A: " . find_in(\%hash , 'A') . "\n";
print "B: " . find_in(\%hash , 'B') . "\n";
print "B: " . find_in(\%hash , 'B') . "\n";
}
print "# NO workaround:\n";
look_for_data();
print "# WITH workaround:\n";
$::WORKAROUND=1;
look_for_data();
=begin perlmonk_comment
####
# NO workaround:
D: xxx
A: no result
B: xxx
B: no result
# WITH workaround:
D: xxx
A: xxx
B: xxx
B: xxx
=cut
#