Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
1. I don't know of any way to cause a hash key to be created by use of an "if" test.

Correct. There isn't. An other operator has to come into play. However, the following fools many since the operator is invisible:

if ($hash{foo}{bar}) download

See my reply to the OP. Interesting...I will have to experiment with this. 2nd hash dimension wasn't part of the question.

2. I don't know of any way to cause a hash key's value to be "non-existant".

delete $hash{foo}; delete @hash{qw( foo bar )}; delete local $hash{foo}; # Since 5.11.0 delete local @hash{qw( foo bar )}; # Since 5.11.0
I'm only on 5.10, so learned something new. Update: still don't see it, ie. how to leave the key but have the value of that key be anything other than undef,string(null or not) or number. To the best of my knowledge a hash key will always evaluate to at least undef. delete $hash{foo} removes key foo and its value.
When you test a hash key, you are testing the value of the key. It can be true or false. false values are: "undef","",'',0

The string "undef" isn't false. Plain old undef is, though.
Yes this was a typo, quotes were wrong to use.

The second and third literal you posted are the same value.

And you're missing some. Except for some insane situations, anything that stringifies to "" or "0" is false. The common false values are undef, the empty string, 0 and "0".
no disagreement here. 0 and "0" I believe will wind up being in practice the same thing.

4. If a hash key value "exists" then it can have any one of the 4 values above. Not true. Aside from the fact that you only listed three values, a hash value can be an scalar, not just false ones. 5. If a hash key value is "defined", then there only 3 possibilities. Not true. It can be any scalar value except undef.
I meant the false values, you are correct.
Update: Added lots as I found that every claim had serious errors.
perhaps not one of my better posts..posted code works as claimed, but explanation could have been better.

Thanks for your clarifications.


In reply to Re^3: Best Hash Practices? by Marshall
in thread Best Hash Practices? by DamianKaelGreen

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 admiring the Monastery: (3)
As of 2024-04-19 22:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found