How to clear a Perl hash

Viewed 70897

Let's say we define an anonymous hash like this:

my $hash = {};

And then use the hash afterwards. Then it's time to empty or clear the hash for reuse. After some Google searching, I found:

%{$hash} = () 

and:

undef %{$hash}

Both will serve my needs. What's the difference between the two? Are they both identical ways to empty a hash?

2 Answers
Related