Unless an object provides a stringification operation using
overload, it is guaranteed that no two references at the same time will stringify in the same way. So yes, you can use them in a hash.
However if you allocate, free, then reallocate a variable, the second one may be used where the first one was. For instance consider this code:
sub gen_ref {
[@_];
}
print gen_ref(), "\n";
my $keep_ref = gen_ref();
print $keep_ref, "\n";
print gen_ref(), "\n";
If you run that, you will find that the first two references that were generated at different times were named the same as each other. But when you tried to create a new one while the old one existed, Perl gave it a different name. So if the hash keys live longer than the references you are indexing into, then you may have a problem.
What is going on behind the scenes is that the name specifies the memory location where you used the data. And if Perl can it reuses the old memory location. If that is in use, then it uses a new one.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.