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

Reply via email to