Multiple choice technology programming languages

Which of the following is the correct way of sorting an array of integers in ascending order?

  1. sort @a

  2. sort {$1 <=> $2} @a

  3. sort {$a <=> $b} @a

  4. sort {$[0] <=> $[1]} @a

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

Perl uses the spaceship operator &lt;=&gt; inside a block to perform numerical comparisons for sorting, using the special package variables $a and $b. The default sort function performs ASCII-alphabetical sorting, while using $1 and $2 or $_[0] and $_[1] inside the sort block is syntactically incorrect.