Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2021-04-17 05:21 GMT
Find Nodes?
    Voting Booth?

    No recent polls found