In (syntax) version 8 and later, the number of values of a variable may be obtained with the $#var syntax. See here for details.