in reply to size of array from ref
I suspect (scalar @{$aref}) actually builds the array again, just to size it. The array is large, so this is slow.....
Well, no. scalar @$array_reference will do what you want it to do. Dereferencing is not copying, you're just re-shaping it temporarily, so it can be used as if it were a real array (surprise: with @$ref, you HAVE a real array in every way. It's not a copy, it's the array $ref is referencing to).
The reference doesn't hold the actual array, it merely refers (points) to it. The array itself is somewhere else in memory, and may or may not have a normal @foo name, or maybe multiple. By dereferencing, you tell Perl to use the array instead of the reference.
U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk
|
|---|