johnnywang has asked for the wisdom of the Perl Monks concerning the following question:
I thought a test such as "if $hash->{1}" wouldn't change $hash, but apparently it does. Is this a well-known behavior, and what's the reason for it? I fully appreciate that "$hash->{1} = 1;" would create the hash.use strict; my $hash = undef; print "shouldn't print\n" if $hash; # prints nothing print 1 if $hash->{1}; # should be a no-op, but it makes $hash to be { +} print "Still shouldn't print, but it does.\n" if $hash; # prints
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why does testing a key create a hash?
by Roger (Parson) on Aug 17, 2005 at 22:01 UTC | |
by friedo (Prior) on Aug 17, 2005 at 22:39 UTC | |
|
Re: Testing a key creates a hash
by davido (Cardinal) on Aug 17, 2005 at 21:54 UTC | |
by tye (Sage) on Aug 17, 2005 at 23:39 UTC | |
by davido (Cardinal) on Aug 18, 2005 at 00:17 UTC | |
by tye (Sage) on Aug 18, 2005 at 00:42 UTC | |
|
Re: Why does testing a key create a hash?
by brian_d_foy (Abbot) on Aug 17, 2005 at 23:23 UTC | |
|
Re: Why does testing a key create a hash?
by zentara (Cardinal) on Aug 18, 2005 at 13:33 UTC |