What will the contents of @b array ? my @a = (10, 5, 1); my @b = sort @a;
-
(1, 5, 10)
-
(1, 10, 5)
-
(10, 5, 1)
-
(5, 10, 1)
Perl's sort function defaults to lexicographic (string) comparison, not numeric. The strings '10', '5', '1' sort as '1' < '10' < '5' because '1' < '5' alphabetically. So @b becomes (1, 10, 5). Option A is incorrect because it assumes numeric sorting.
To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) (1, 5, 10) - This option is incorrect because it is not the correct sorted order of the elements in the array @a.
Option B) (1, 10, 5) - This option is the correct answer. When we sort the elements in the array @a, the result is (1, 10, 5) because the elements are sorted in ascending order.
Option C) (10, 5, 1) - This option is incorrect because it is not the correct sorted order of the elements in the array @a.
Option D) (5, 10, 1) - This option is incorrect because it is not the correct sorted order of the elements in the array @a.
The correct answer is B. This option is correct because when we sort the elements in the array @a, the result is (1, 10, 5).