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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|