Multiple choice technology programming languages

Consider the following lines of code: @array1 = ("apples", "oranges", "pears", "plums"); foreach (@array1) {print "$_\n"}; What is the result of these lines of code?

  1. applesorangespearsplums

  2. apples oranges pears plums

  3. apples

  4. apples oranges pears plums

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

The foreach loop iterates through @array1. Inside, $_ becomes each element. print "$\n" prints each element followed by newline. But since print is called without comma between $ and \n in double quotes, it prints each element with whitespace around it from the array's internal storage, resulting in spaces between words. Option D best represents this output.