Among the excellent replies above I don't think anyone explained explicitly why you are getting the answer 1 from
length, although maybe it is implied.
length takes a scalar, so it uses
keys %$hashref in scalar context. That gives 3, but
length converts that to text '3', which is 1 character.
For example:
use warnings;
use strict;
my $hashref = {1..20};
print scalar(keys %$hashref)."\n";
print length keys %$hashref;
Gives:
10
2
because there are 2 characters in "10".