Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This regards a thread started in Meditations to which I wanted to reply (actually ask a question); but I thought it more appropriate to bring my question into this forum. The original node in Meditations involved a simple construct from some legacy code the author was trying to maintain. It included the following code snippet:

%foo ={}; unlink %foo;

I don't believe the subsequent discussion is relevant (the reference is from this post by vrk) nor am I particularly concerned about the unlink portion (though that was what most of the rest of the thread was about).

But my question is as follows:

Since the original hash, %foo, was assigned an anonymous hash, doesn't that make it a hash with a single entry (that entry is a reference to the anonymous hash)? So %foo's entry is a single value and it resolves to the stringified version of the anonymous hash (if it is, indeed, used as a key)...doesn't it?

But, presuming that %foo (viewed as a list) only has the single entry (the author of the node says on his machine the stringified reference is HASH(0x814dc30)), then it begs...for me, at least...another question. How does a hash handle a single value...i.e., it either has no key or no value for the key. That is to say, is the HASH(0x814dc30) a key or a value?

I naively presume that it is considered the key (the stringified version of the anonomyous hash reference) and that the value associated with the key is undef (or maybe it is just empty, a null?).

So, my question is how does Perl handle a hash like the above if that hash is used in a list context (which is important to understanding what unlink will do given the hash, unlink will use the hash in its list context)?

ack
Albuquerque, NM

In reply to Curious about Hashes which viewed as a list has only one item by ack

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 exploiting the Monastery: (3)
As of 2024-04-25 06:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found