
LerdoPerlo
New User
Feb 22, 2010, 9:13 AM
Post #1 of 4
(333 views)
|
|
2D array length (again!)
|
Can't Post
|
|
Hi, I'm sure this has been asked several times before, but I can't seem to find a proper answer. Say I have the following two-dimensional array:
@A = ( [00, 01, 02, 03], [10, 11, 12, 13, 14, 15, 15, 17, 18], [20, 21, 22, 23, 24, 25, 26, 27], [30, 31], [40], [50, 51, 52] ); I've found that if I print the size of @A using:
print "size of A: " . @A . "\n"; I get the expected value: 6 But if I try to find the size of each of the arrays within @A and I go further than its real size, that is:
print "size of A[0]: " . $#{$A[0]} . "\n"; print "size of A[1]: " . $#{$A[1]} . "\n"; print "size of A[2]: " . $#{$A[2]} . "\n"; print "size of A[3]: " . $#{$A[3]} . "\n"; print "size of A[4]: " . $#{$A[4]} . "\n"; print "size of A[5]: " . $#{$A[5]} . "\n"; print "size of A[6]: " . $#{$A[6]} . "\n"; print "size of A[7]: " . $#{$A[7]} . "\n"; print "size of A[8]: " . $#{$A[8]} . "\n"; The next time I print the size of @A, it says it's now 9 elements big. Furthermore: How one would add a new column in the last row (ie, an element to the last array of @A)? I was expecting this to work, but didn't:
$A[ @A -1 ][ $#{$A[ @A -1 ]} ] = "new element";
|