There are very few situations where you would want to treat hash keys the same as hash values, which is what you are doing when you grep { ... } %hash, or foreach ( %hash ) { ... }. That's probably bug as a consequence of not understanding how to use Perl's hashes. It often does make sense to iterate over a hash's keys (generate a list of them using keys), or a hash's values (values). Likewise, my( %hash ) = <INFILE> is almost certainly a bug too, unless your input file looks like this:

some key some value some key some value

...which is unlikely in general, and definitely not the case for your data sets.

I'm going to assume that you're required, for some reason, to use newline delimited flat files for your inventory list, and your storage list. Though it's probably not the most time-efficient approach, I would probably just use Tie::File, and be done with it.


Dave


In reply to Re: Deleting a word in a file! by davido
in thread Deleting a word in a file! by Jabox

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.