Multiple choice perl

Pick the odd one out

  1. ord

  2. sort

  3. reverse

  4. foreach

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

The 'foreach' keyword is the odd one out because it's a looping construct that iterates over a list (a control flow statement), whereas ord(), sort(), and reverse() are all built-in functions that transform and return values. Functions like ord (converts character to ordinal), sort (orders a list), and reverse (flips a list) are operators that take input and produce output, while foreach executes a block of code for each element.

AI explanation

To answer this question, we need to identify the option that does not fit with the others.

Option A) ord - The ord function is used to return the ASCII value of a character. It is a valid function.

Option B) sort - The sort function is used to sort an array or a list in ascending order. It is a valid function.

Option C) reverse - The reverse function is used to reverse the order of elements in an array or a list. It is a valid function.

Option D) foreach - The foreach loop is used to iterate over elements in an array or a list. It is different from the other options, which are functions or methods. It is the odd one out in this context.

Therefore, the correct answer is D) foreach.