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'.

In reply to Re: How to set hash values to '-' . by dsheroh
in thread How to set hash values to '-' . by Sami_R

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.