Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to set hash values to '-' .

by dsheroh (Monsignor)
on Jun 14, 2020 at 11:04 UTC ( #11118044=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11118044]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2020-10-20 09:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (209 votes). Check out past polls.

    Notices?