SPUG: scalar(@array)

Alan E. Derhaag aderhaa at n2h2.com
Thu Apr 13 19:25:35 CDT 2000


"Patterson, David S (David)" <davidpa at lucent.com> writes:

> Hmmm...  Very perplexing...  Running the following program
> 
>   @array = (aa, bb, cc, dd, ee);
>   print @array, '  ', scalar (@array), "\n";
>   undef $array[3];
>   print @array, '  ', scalar (@array), "\n";
>   print @array, '  ', $#array, "\n";
> 
> gives the following output:
> 
>   aabbccddee  5
>   aabbccee  5
>   aabbccee  4
> 
> What does this mean?  Are there 4 elements or 5?
> 

Did you forget that $#array is actually the offset (number of last
element) and not actually a count (add 1 to include the 0th element).

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace "action" below by subscribe or unsubscribe
           Email to majordomo at pm.org: "action" spug-list your_address





More information about the spug-list mailing list