I have these two snippets of code which seemingly should produce the same result, but the latter results in an error.
1:
my $href = undef;
my @values = values %{ $href };
# OK - @values is empty
2:
my $href = undef;
my %hash = %{ $href }; # <-- Error here
my @values = values %hash;
# ERROR: Can't use an undefined value as a HASH reference
Why does having values
in the same line allow it to work? I'd rather them both throw an error, since using an undefined value as a hash reference is clearly a mistake. I don't have any more recent versions of perl to test on, but this was reproducible in 5.8.8 and 5.10.1.