If case-insensitive lookup (and storage) of the usernames is the idea, then you could apply the same case transformation on the hash key (all uppercase, all lowercase, etc.) prior to storing the entry, and then similarly upon lookup, e.g.

... $name_hash{uc $username} = $password; ... while(<STDIN>) { chomp; exit if $_ eq 'exit'; my $name = uc $_; if (exists $name_hash{$name}) { print "The password for $name is $name_hash{$name}, please ent +er another name to search\n"; } else { print "I'm sorry, there is no one here by that name, please tr +y another name or type exit to end.\n"; } }

This would simplify things by taking advantage of hashes' key feature (pun intended) to allow a direct lookup, without having to loop over all of its entries.

Note that this suggestion differs slightly from what your code does, in that yours will (a) find the name even if only a substring of it has been specified as the lookup string, and (b) will return multiple matches if the hash happens to be storing several differently spelled variants (Name, name, NAME, ...) of the same username...  I'm not sure whether you actually need those features, so I'm mentioning this simplification just in case my suspicion should hold true that you don't... :)


In reply to Re: No <STDIN> yeilds username and password by almut
in thread No <STDIN> yeilds username and password by trenchwar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.