Why use an iterator when you can go straight to the horse's mouth? Try
exists on the string and if you miss, try
exists on a lower-case version of the string?
use strict;
sub find_inB {
my ($data_hr, $string) = @_;
my $no_result = 'no result';
return (
exists $$data_hr{ $string }
? $$data_hr{ $string }
: exists $$data_hr{ lc $string }
? $$data_hr{ lc $string }
: $no_result
);
}
sub look_for_dataB {
my %hash = map { ($_, 'xxx'); } qw( A B C D );
print "D: " . find_inB(\%hash , 'D') . "\n";
print "A: " . find_inB(\%hash , 'A') . "\n";
print "B: " . find_inB(\%hash , 'B') . "\n";
print "B: " . find_inB(\%hash , 'B') . "\n";
}
print "# look_for_dataB:\n";
look_for_dataB();
__END__
# look_for_dataB:
D: xxx
A: xxx
B: xxx
B: xxx
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.