P is for Practical | |
PerlMonks |
Re: Allocation of anonymous arraysby Athanasius (Archbishop) |
on Feb 07, 2014 at 09:46 UTC ( [id://1073846]=note: print w/replies, xml ) | Need Help?? |
Hello OwlHoot, and welcome to the Monastery! Consider:
Would Perl see that both arrays contain the same values, and therefore “optimise” the storage by having @foo and @bar refer to the same set of storage locations? No, because these arrays must be allowed to change independently. For example, incrementing $foo[0] should have no impact on the value of $bar[0]. Now, an anonymous array is just an array which is accessed by a reference rather than a name. Two anonymous arrays which happen to share the same data cannot be optimised to refer to common storage, because either is free to change independently of the other as the script runs. So, I think your colleague is correct. But — please explain the motivation for using array references as hash keys in this way?!? Hope that helps,
In Section
Seekers of Perl Wisdom
|
|