How can I undefine the value for a hash key in Perl? How can my code be corrected?
#!/usr/bin/perl
use strict;
use warnings;
my %hash;
undef($hash{"a"});
undef($hash{"b"});
print scalar values %hash; # Here I need 0
print scalar keys %hash; # And 2 here
Alexandr Ciornii’s point about definedness vs. existence is a very good one, but if you actually do want to know the number of defined values, you can always do: