Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

(jjhorner)Finding the total number of elements in an array.

by jjhorner (Hermit)
on Jul 19, 2000 at 16:15 UTC ( [id://23167]=note: print w/replies, xml ) Need Help??


in reply to Finding the total number of elements in an array.

You can get the index of the last element of the array by:

$#arrayname

Which can be used like this:

my $i; for ($i = 0; $i <= $#arrayname; $i++) { #do something }

And getting the total number of elements is as easy as:

my @stooges = qw(Larry Moe Curly); print scalar(@stooges), " Stooges!\n";
J. J. Horner
Linux, Perl, Apache, Stronghold, Unix
jhorner@knoxlug.org http://www.knoxlug.org/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found