Finding Total Count of Items in a List
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:
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?