Empty Hash Values

Leo Lapworth leo at cuckoo.org
Sun Apr 12 19:30:11 BST 2009


2009/4/12 Nigel Peck <nigel.peck at miswebdesign.com>

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


I can not replicate this... code below?

I'm on perl v5.8.8


use strict;
use warnings;

my $var;
my $var2 = 'bla';

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

use Data::Dumper;
print Dumper($hash);

> perl test.pl
$VAR1 = {
          'element_3' => 'bla',
          'element_2' => undef,
          'element_1' => 'example'
        };


More information about the london.pm mailing list