http://qs321.pair.com?node_id=11118044


in reply to How to set hash values to '-' .

You forgot to mention how the hash is being created and how it's being output in the first place. If you want the '-' values to actually be in the hash, then how it's created is very significant to being able to answer the question, and if you don't want them to actually be in the hash, then how it's output is equally significant.

But I guess there's a simple (if verbose) way to add them, regardless of how it was created, because the right side of a hash assignment is really just a list, and values later in the list supersede those earlier in the list:

%the_hash = ( day => '-', Balance => '-', payment => '-', Total => '-', %the_hash );
This will preserve any existing values in the hash, while adding them for any keys that are missing:
$ perl -MData::Printer -E "%h = (day => 1, Total => 2); %h = (day => ' +-', Balance => '-', payment => '-', Total => '-', %h); p %h;" { Balance "-", day 1, payment "-", Total 2 }
And you should really standardize on either starting all the keys with lowercase or all with uppercase. Having them mixed is going to cause you (and anyone else who works on this code) all kinds of headaches when you try to access the keys 'Day', 'balance', 'Payment', or 'total'.