CIW Exam Questions

What is the output of these lines of code?

Consider the following lines of code:
1.$playerStr = “Today’s player is Bob Petit.”;
2.if($playerStr =~ /[Ruth|Gehrig|DiMaggio]/) {
3. $game = “Baseball”;
4.}else{
5. $game = “Basketball”;
6.}
7.print $game;
What is the output of these lines of code?

A.
No output is generated due to an error in line 2.

B.
Basketball

C.
Baseball

D.
No output is generated due to an error in line 3.

Explanation:

[Note] /[ Ruth|Gehrig|DiMaggio ]/ <=> /[ RuthGehrigDiMaggio ]/
don’t confuse with /( Ruth|Gehrig|DiMaggio )/