I updated my post with some more test cases. defined and exists behave similarly in regards to generating intermediate keys in the process of doing their work. I show an example of how to prevent this below.

I don't know if this helps or not, but checking for defined vs or exists can generate hash entries.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash = ('key' => 'value'); print Dumper \%hash; #prints: #$VAR1 = { # 'key' => 'value' # }; print "defined\n" if defined $hash{abc}{xyz}; # will create new keys print "defined\n" if defined ($hash{x}) and defined ($hash{x}{y}); # a +dded: won't create new keys print "exists\n" if exists ($hash{x}) and exists($hash{x}{y}); # a +dded: won't create new keys print "exists\n" if exists $hash{x1}{x2}; # added: will create new +keys print "defined\n" if defined $hash{x3}; # added: no new key print Dumper \%hash; __END__ #prints: # The "abc" key is created due to the check for defined of 2nd dimensi +on # exists will also create new intermediate keys $VAR1 = { 'key' => 'value', 'abc' => {}, 'x1' => {} };
Sometimes you have to check at each level if the hash "dimension" exists. A check for "defined" or "exists" can generate automatic dimensions.
Sometimes you have to you have to check whether some hash key exists at all before checking what its value is (defined or not).

In reply to Re: Strange memory growth by Marshall
in thread Strange memory growth by spica1001

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.