Empty Hash Values

Nigel Peck nigel.peck at miswebdesign.com
Sun Apr 12 18:54:55 BST 2009


When I create a hash like this:

my $hash = {
	element_1 => 'example',
	element_2 => $var,
	element_3 => $var2
};

If $var is undefined, then the value of 'element_2' becomes 'element_3'. 
Not what I want.

The only way round this I've found is to concatenate an empty string:

my $hash = {
	element_1 => 'example',
	element_2 => $var .'',
	element_3 => $var2
};

Ugh. I'm sure there's a better way?

Thanks in advance,
Nigel


More information about the london.pm mailing list