Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Unique value count in hash not working properly

by keszler (Priest)
on Sep 30, 2011 at 13:27 UTC ( [id://928801]=note: print w/replies, xml ) Need Help??


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';

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://928801]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-23 22:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found