Multiple choice technology programming languages

($t, @u, $v, @w ) = qw( India US Japan Spain Mexico China ). How many elements are assigned to @u,@w?

  1. 1 and 2

  2. 5 and 0

  3. 1 and 3

  4. none of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In Perl list assignment, scalars consume single elements while arrays consume remaining elements. Here, \$t gets 'India', @u consumes all remaining elements ('US', 'Japan', 'Spain', 'Mexico', 'China' - 5 elements), leaving nothing for \$v and @w. Therefore @u has 5 elements and @w has 0.