in reply to Ludicrously Stupid Foreach Loop Question
Then do what you need to do with the hash, eg:my @old_stock1 = ('products','here'); my @old_stock2 = ('products','here'); # define hash to store quantities my %new_stock; # iterate through old for (@old_stock1, @old_stock2) { # add one to count for this element # (creating it if it doesn't exist) $new_stock{$_}++; }
would list name and quantity of each item.for (keys %new_stock) { print "$_ = $new_stock{$_}\n"; }
cLive ;-)
ps - Update - oops, just re-read the question. See below (but the principal still stands :) - pjf seems to have covered it.
|
|---|