PrepAway - Latest Free Exam Questions & Answers

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?

PrepAway - Latest Free Exam Questions & Answers

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 )/

One Comment on “What is the output of these lines of code?


Leave a Reply