Multiple choice technology programming languages

Which of the following commands should be used to open a filehandle named KAREN to an existing file named sw?

  1. open KAREN ">sw";

  2. open KAREN, ">sw";

  3. open "sw" KAREN;

  4. open ">sw", KAREN;

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

The correct Perl syntax is open KAREN, ">sw"; which opens filehandle KAREN for writing to existing file sw. The > mode opens for writing, and the comma separates the filehandle from the filename string. Option A is missing the comma separator, while C and D have incorrect argument order.