53

Variables
Size of List Variables

  • There are two different ways to compute the size of a list variable. Careful, they yield two different results...

      @foo = ( "apple", "bat", "cat" );

  • Get the number of elements contained in the list

      $size = scalar( @foo ); # Yields 3

  • Get the index for the last element contained in the list

      $size = $#foo; # Yields 2