Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-25 10:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found