Multiple choice technology programming languages

@array= (“one”,”two”,”three”,”four”,”five”); @sublength = (1,2,3); @sub_array = @array[@sublength]; print @sub_array;

  1. one two three

  2. two three four

  3. 3

  4. Error:unknown array

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

@array[@sublength] uses array slicing with indices from @sublength. Indices 1, 2, 3 select elements at those positions: 'two' (index 1), 'three' (index 2), and 'four' (index 3). Arrays are 0-indexed.

AI explanation

@array[@sublength] is an array slice: it takes each value in @sublength (1, 2, 3) and uses them as indices into @array. Perl arrays are zero-indexed, so index 1 is 'two', index 2 is 'three', and index 3 is 'four'. That gives @sub_array = ('two','three','four'), matching the marked answer. 'one two three' would result from indices (0,1,2) instead, '3' is just the slice's length/last index misread, and there's no error — array slicing with a list of valid indices is perfectly legal Perl syntax.