First, I want to say, I've made some typos in my code. I've used '=' instead of '=>' in hashes and I've forgot to apply a value in the subroutine. I fixed it now.

Anyway.

The obvious, as you say, yes. That's how I usually do it. I, usually, create a sub, supply the values explicitly to it and get the result. I just wanted to see, if it's possible to do it implicitly, also, I need that total value in the variable, because I am going to sort it by qtyTotal in dec order, by using a sort function. If it's not going to be automatically updated, I figure that I have to create an other temp variable, every time I use that sort function. I just wanted to see, if could it be done in a more elegant way. Also, it will eliminate any bugs, that could be caused by forgetting of updating a qtyTotal in that variable.

I guess, you are right about creating object instead of just using a regular variable.

I was hesitant with that because, the only time, I've used objects is when I refer to other libraries or modules and what always stopped me was that, i might be wrong, the requirement to create a module, describing the object in the separate file instead of just ability to make an object in the same file as the script. :(

In reply to Re^2: How to detect a hash container key from a referenced sub value by igoryonya
in thread How to detect a hash container key from a referenced sub value by igoryonya

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.