in reply to Clear / Initialize multiple hashes
"my" variable %hash1 masks earlier declaration in same scope
So, the statement is equivalent to
my (%hash1, %hash2, %hash3);
Note that the hash %_ is not cleared, because the body of the loop is not run (the brand new hashes are emtpy).
Without my, %_ would be cleared, but %hash1 and company would stay untouched. To test, just play with comments in the following code:
# use strict; use warnings; %_ = (u => 2); %hash1 = (b => 3); # %hash1 = (b => 3); # %_ = () for my (%hash1,%hash2,%hash3); # %_ = () for (%hash1,%hash2,%hash3); print %_, %hash1, "\n";
To clear a hash, use undef or %hash = ().
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Clear / Initialize multiple hashes
by acadey (Initiate) on Sep 19, 2013 at 18:19 UTC | |
by BrowserUk (Patriarch) on Sep 19, 2013 at 18:45 UTC | |
by choroba (Cardinal) on Sep 19, 2013 at 18:23 UTC |