Merging a blank hash

D

Derek Basch

If I am merging a blank hash into a populated hash how do I prevent
blank key/value pairs from being created?

This:

my %hash1 = ();
my %hash2 = (
key1 => 'cat',
key2 => 'dog'
);

my %hash3 = (%hash1, %hash2);

while (my ($key, $value) = each(%hash3)) {
print "$key: $value\n\n";
}

outputs:
 
I

it_says_BALLS_on_your forehead

Derek said:
If I am merging a blank hash into a populated hash how do I prevent
blank key/value pairs from being created?

This:

my %hash1 = ();
my %hash2 = (
key1 => 'cat',
key2 => 'dog'
);

my %hash3 = (%hash1, %hash2);

while (my ($key, $value) = each(%hash3)) {
print "$key: $value\n\n";
}

outputs:
-----------------
key2: dog

key1: cat

------------------

Are you sure the newlines aren't from the extra newline you are
printing out after the value?
 
D

Derek Basch

it_says_BALLS_on_your forehead said:
Are you sure the newlines aren't from the extra newline you are
printing out after the value?

OMG. Sulks away in idiocy. Thanks. Sorry.
 
I

it_says_BALLS_on_your forehead

Derek said:
OMG. Sulks away in idiocy. Thanks. Sorry.

Are you sure you don't mean "skulks"? ;-).

No worries. I've done LOTS of idiotic things, and I've only been in the
business for 2 years.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top