Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
It's a bit unfair to blame autovivification for your typo. Even without the typo, the value of $exists is possibly wrong. And a good test suite would have tested for this - it would have run a text which would set $exists to a true value. And then fail because that didn't happen.

But the problem is deeper. The problem is using string literals as hash keys, because that more or less turns hash elements into variables - with all the drawbacks of package variables, and then some. If you want a variable, use a (preferably) lexical variable. Don't fall for the sweet lures of "oh, just stuff it into a hash" - it's worse than turning off strict. If you do need to populate a hash, put the index into a constant (with Readonly) or a variable.

Remember the old rule "never put magic numbers inside your program - use constants". But that applies to strings as well. Don't use string literals - use constants. And don't blame autovivification if you do use string literals and burn yourself.


In reply to Re: The Bad, the Ugly, and the Good of autovivification by Anonymous Monk
in thread The Bad, the Ugly, and the Good of autovivification by tlm

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (5)
    As of 2014-09-21 07:10 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (167 votes), past polls