Empty Hash Values

Uri Guttman uri at stemsystems.com
Sun Apr 12 19:43:20 BST 2009

>>>>> "NP" == Nigel Peck <nigel.peck at miswebdesign.com> writes:

  NP> When I create a hash like this:

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

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

that isn't what should happen. this shows that:

perl -MData::Dumper -le '$h = { a => $x, b => 3 }; print Dumper $h'
$VAR1 = {
          'a' => undef,
          'b' => 3

a scalar var which is undef will take up any scalar value location
including one in a hash. now if you had an empty array there, that is a
different story. so show some real code that demonstrates what you think
is the problem. your original code doesn't show it as my code proves.


Uri Guttman  ------  uri at stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

More information about the london.pm mailing list