in reply to Filling a Hash

When you do

%customer_domain_hash = split(/@@@/, $line);

you are overwriting the entire hash every time whereas what really ought to happen is that only one entry should be added/changed. So, if you replace that one line with:

my ($key, $value) = split(/@@@/, $line); $customer_domain_hash{$key} = $value;

it should build up the hash on each iteration of the foreach.

Update: Unless you have duplicate keys, of course, which has been pointed out below (thanks, GotToBTru). A simple hash is not sufficient to store this. toolic's answer shows an alternative approach.

Replies are listed 'Best First'.
Re^2: Filling a Hash
by GotToBTru (Prior) on Jul 17, 2015 at 15:52 UTC

    Almost! He will end up with just 2 entries in the hash because the key repeats.

    Dum Spiro Spero
Re^2: Filling a Hash
by Nemo Clericus (Beadle) on Jul 17, 2015 at 14:09 UTC
    Good solution. To clarify for the OP, the statement that has been fixed here was essentially akin to saying "Make my hash an array". Whereas what you should be doing is assigning a particular key in the hash a value. Pardon me if I'm pointing out something obvious - not sure how much of a newbie you are! :)