This data is checked carefully on input and output. When undef gets somehow into hash then error is thrown.

Ok, I see. Although of course there are exceptions, I find it easiest to work with hashes in one of two ways: either a fixed set of possible keys, in which case one can avoid autovivification issues by not differentiating between exists and defined, so it doesn't matter whether a key is present or not, and undef simply indicates "no value". Or, the other situation is a set of keys that is unknown to the code beforehand, in which case one generally only iterates over the hash with keys etc., and one doesn't generally access specific hash keys by name.

It sounds like you might be mixing these two - although there are sometimes valid cases where a hash has a known set of keys and one does want to differentiate between exists and defined, I've found this to be a little annoying to work with. For example, in my module IPC::Run3::Shell, there are options that can be exists but not defined, but then there is no easy way to override these options so they no longer exist in the hash.

Anyway, In the code you showed, I might have gone with exists checks to prevent autoviv, even if that makes the code more verbose.


In reply to Re^2: Sometimes undef is initialized and sometimes not when hash values are fed to grep by haukex
in thread Sometimes undef is initialized and sometimes not when hash values are fed to grep by leszekdubiel

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.