in reply to Unique value count in hash not working properly

Incidentally, your

if ($count{$batch_dates}) { $count{$batch_dates}++; } else { $count{$batch_dates} = 1; } # end if
could be replaced by just
$count{$batch_dates}++;
If no $batch_dates key previously existed in %count, then the first use of it with ++ will autovivify (with numeric value zero) and increment to 1.

Replies are listed 'Best First'.
Re^2: Unique value count in hash not working properly
by Anonymous Monk on Oct 01, 2011 at 00:02 UTC

    Assignment, bar key is assigned the value 1
    my %foo; $foo{bar} = 1;

    Autovivification, a hashref springs into existence under key fa , bar key is assigned the value 1

    my %foo; $foo{fa}{bar} = 1;

    Autovivification, you use it as a reference to a hash, , it becomes a reference to a hash

     my $foo; $foo->{bar} = 1;

    Autovivification, you use it as a reference to an array, it becomes a reference to an array

     my $foo; $foo->[0]= 1;

    Initialization, you declare $foo and assign a reference, you can use it as a reference, but it doesn't become a reference, because it already is a reference

     my $foo = {}; $foo = \my %bar; $foo->{fa} = 1;

    Error, can only autovivify if undef, Not an ARRAY reference

     my $foo = {}; $foo->[0] = 1;

    Error, can only autovivify once, Not a HASH reference

     my $foo; $foo->[0] = 'autovivified'; $foo->{autovivified} = 'already';