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

In Perl, the open function requires a filehandle and an expression specifying the mode and filename, separated by a comma. open KAREN, ">sw"; correctly opens the file sw for writing (indicated by >) using the filehandle KAREN. Other options either omit the comma or reverse the argument order, which are syntactically invalid.