Even if the contents of the hash are the same each time you call the sub, it's still a different hash. To take the most trivial example:
sub get_hashref {
my %hash;
return \%hash;
}
it creates a new
my %hash each time it's called, since the old one went out of scope and no longer exists
1. If you want to prove this to yourself, create a trivial sub like that and call it twice, storing both hashrefs. Add some data to one hashref, then look in the other - it will still be empty.
(There are ways to have it return references to the same hash every time it's called, such as
my %hash;
sub get_hashref2 {
return \%hash;
}
but defectdata() apparently doesn't do this.)
1 Not entirely true, in that the previous hash still exists and can be accessed by the previously-returned hashref, but it has become anonymous and is no longer my %hash. Read up on "closures" for more about how this works (and how it can be used to do some pretty powerful stuff).
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.