Sample codes:
Sample run:
Could someone show me how to distinguish them? Thanks.
Code:
use Data::Dumper;
my %h;
$h{a} = undef;
$h{b} = '';
$h{c} = 'z';
print Dumper(\%h); # [b]Dumper can distinguish the difference between $h{a} and $h{b}[/b]
foreach my $k (keys(%h)) {
[b]# The following block cannot distinguish the difference between $h{a} and $h{b}[/b]
if(!$h{$k}) {
print "Undefined hash value: Key - $k\n";
}
else {
print "Key: $k, Val: $h{$k}\n";
}
}
Sample run:
Code:
% ./tt.pl
$VAR1 = {
'c' => 'z',
'a' => undef,
'b' => ''
};
Key: c, Val: z
Undefined hahs value: Key - a
Undefined hahs value: Key - b
Could someone show me how to distinguish them? Thanks.