9 Replies Latest reply on Jul 16, 2009 9:41 AM by ChristianAntalics

    Finding Total Count of Items in a List

    crapples

      Title

      Finding Total Count of Items in a List

      Post

      I have struggled with this for a while:  If I have a list of inventory items - thousands of them - and I want to get a total count for each item and return that count to a variable, what is the best way to do this?

       

      To clarify, if I have this list:

       

      widget1

      widget2

      widget2

      widget3

      widget1

      widget1

       

      I want to run a script that returns a variable (called $counts) that containes the item names followed by how many of them I have.  Like this: widget1;3 | widget2;2 | widget3;1

       

      I've been doing this by sorting the inventory list and looping down the entire thing counting as I go along, but it seems like there must be a better way.  Is there a way to introduce a summary calculation or something else that would make this process more natural?

       

      Thanks!