Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Length of 2-dimensional array

by satchboost (Scribe)
on Apr 05, 2001 at 23:17 UTC ( [id://70234]=note: print w/replies, xml ) Need Help??


in reply to Length of 2-dimensional array

Maybe I'm missing something, but wouldn't $#array give you the length of the array? n-dim arrays are really simple arrays, all of whose elements are references to arrays (and so forth for dimensions > 2). Thus, the length is the size of outer-most array. Right?

Replies are listed 'Best First'.
Re: Length of 2-dimensional array
by tedv (Pilgrim) on Apr 06, 2001 at 00:50 UTC
    First, $#array is the index of the last element in the array. This is never the length of the array itself (unless you've mucked with $[, but don't do that). The best way to get the length of an array is to evaluate it in scalar context.

    Second, they haven't defined what the "length" of the two dimensional array is, so it's very difficult to answer the question. Is "length" the length of the longest sub-array? The number of elements in the the main array? The total of all "end level" elements in the array? So maybe your definition of length is what he needs and maybe it isn't.

    Incidently, Tye already illustrated the issues with the length concepts in another replay: each of the N different Sub-arrays could have different lengths from each other.

    -Ted

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://70234]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found