Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How do I find the size of an array?

by dsb (Chaplain)
on Jan 24, 2001 at 19:47 UTC ( [id://54001]=note: print w/replies, xml ) Need Help??


in reply to How do I find the size of an array?

Very simply. Evaluate the array in scalar context.
$size = @array;

Remember that the size of an array is not the same as the last element of an array. Since indexing of elements starts at zero, the last element of a ten-element array is 9. See the following code:

my @array = qw/1 2 3 4 5/; print scalar @array, "\n"; # Size of array print $#array, "\n"; # Last element of array

And the output:

5
4

Originally posted as a Categorized Answer.

Log In?
Username:
Password:

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

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

    No recent polls found