Perl Monk, Perl Meditation | |
PerlMonks |
Re: the last added element of a hashby Athanasius (Archbishop) |
on Jul 31, 2014 at 09:24 UTC ( [id://1095711]=note: print w/replies, xml ) | Need Help?? |
Hello Lennotoecom, I would re-write this idea as follows:
This gives the same result, but:
This script’s output (like the title of this node) is still somewhat misleading, however, as “last element added” really means “last element added of those still remaining in the hash.” For example, if you add elements X, Y, and Z, and then delete element Z, this script will output Y as the “last element added,” which isn’t strictly correct. But the real problem with this whole strategy is that it relies on an implementation detail of the perl interpreter; namely, that it always assigns new hash values to memory addresses above those of previously-assigned values. Is this guaranteed to be the case? Will it always be true of perl implementations in the future? I don’t know, and for that reason I would advise against this approach until and unless it can be proven to be valid now and also future-proof. Hope that helps,
In Section
Seekers of Perl Wisdom
|
|