in reply to Re: Brain muchly befuddled by nested hashes
in thread Brain muchly befuddled by nested hashes

When you provide a list when referencing a hash element, perl assumes you are using old perl4-style emulated nested hashes and produces a single hash key like this: $ClubTotal{"DayOfMonth$;$date"}.

Based on looking at the OP's output from Data::Dumper (and on trying it myself), it seems that perl is not adding any sort of field delimiter in the hash key:

perl -le '$n=0; $h{"foo"=>$n++}=$n for (0..3); print "$_ => $h{$_}" fo +r (sort keys %h)' foo0 => 1 foo1 => 2 foo2 => 3 foo3 => 4
That said, I would agree that presence of the "fat comma" (=>) as part of the hash-key expression looks like a misunderstanding (and/or could be misunderstood by less skilled readers), and is rather ugly as well. Something like simple concatenation or string interpolation would be clearer ($hash{'string'.$num} or $hash{"string$num"}).

Replies are listed 'Best First'.
Re^3: Brain muchly befuddled by nested hashes
by ysth (Canon) on Nov 24, 2008 at 06:05 UTC
    The delimiter is there, you just don't see it. Hence my comments about Data::Dumper's defaults (added shortly after I first posted, so you may have missed them).
    $ perl -le '$n=0; $h{"foo"=>$n++}=$n for (0..3); use Data::Dumper; pri +nt Dumper \%h; $Data::Dumper::Useqq=1; print Dumper \%h' $VAR1 = { 'foo1' => 2, 'foo0' => 1, 'foo2' => 3, 'foo3' => 4 }; $VAR1 = { "foo\0341" => 2, "foo\0340" => 1, "foo\0342" => 3, "foo\0343" => 4 };