in reply to Unable to create HASH type

anjultyagi:

You're creating the hash value just fine. It's just that when you pass a hash to a function, it's expanding into a list. So when Dumper runs, it's dumping each value in the list separately, so it doesn't look like what you're expecting. Here's an example:

$ cat u.pl use strict; use warnings; use Data::Dumper; my $hashRef = {amountSubmitted=>1}; print "a hash reference: ", Dumper($hashRef), "\n"; my %hash = (amountSubmitted=>0); print "a hash expands to a list: ", Dumper(%hash), "\n"; print "pass the hash as a ref: ", Dumper(\%hash), "\n";

When run, it'll look like this:

$ perl u.pl a hash reference: $VAR1 = { 'amountSubmitted' => 1 }; a hash expands to a list: $VAR1 = 'amountSubmitted'; $VAR2 = 0; pass the hash as a ref: $VAR1 = { 'amountSubmitted' => 0 };

So when you're going to use Dumper to display a hash, be sure to use a hash reference instead of letting the hash expand to a list of values.

You should be aware that the same thing happens with arrays: If you use Dumper on an array, you'll get $VAR=first array value, $VAR=second array value, etc., unless you use an array reference:

$ perl u.pl array reference: $VAR1 = [ 'first value', 'second value' ]; array: $VAR1 = 'first value'; $VAR2 = 'second value'; array as ref: $VAR1 = [ 'first value', 'second value' ];

Update: Added bit about array/arrayref.

...roboticus

When your only tool is a hammer, all problems look like your thumb.