Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Don't ask to ask, just ask
 
PerlMonks  

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

by DrHyde (Prior)
on Oct 14, 2003 at 11:23 UTC ( [id://299143]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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

$#array is the index of the last element in @array. In this case, the # character does NOT introduce a comment.

For example, if you have @array = qw(ant bat cat dog eagle fish ghoti) then $#array is 6 (the index of 'ghoti'). The number of elements in the array is usually $#array + 1.

Note that those values will change if $[ is set to anything other than 0. To cope with those times when someone has been naughty (use of $[ is strongly discouraged), you should get the number of elements in an array by evaluating @array in scalar context, such as:

print scalar @array;
or
$num_elements = @array;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://299143]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.