in reply to Finding the total number of elements in an array.
If you evaluate a named array in a scalar context, it
returns the length of the array. (Note that this is not
true of lists, which return the last value, like the C
comma operator, nor of built-in functions, which return
whatever they feel like returning.) The following is
always true:
scalar(@whatever) == $#whatever - $[ + 1;
(stuff deleted)
So in general you can assume that
scalar(@whatever) == $#whatever + 1;
Some programmers choose to use an explicit conversion so
nothing's left to doubt:
$element_count = scalar(@whatever);
which is about as definitive an answer as you are going to get! maybe this is the "angry old man" in me coming out, but
it kind of ticks me off when it feels like maybe someone didn't research things enough before posting a question... oh well... i won't vote this one down, but i really hope that perlmonks doesn't start getting flooded (like the MySQL mailing list and most other good tech forums that exist) with questions that could have been easilly solved by a quick scan through some documentation...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Finding the total number of elements in an array.
by ferrency (Deacon) on Jul 19, 2000 at 19:37 UTC | |
by eduardo (Curate) on Jul 19, 2000 at 19:49 UTC |