Multiple choice technology programming languages

What gets printed? my $a = 123; my $b = 0123; if ($a == $b) { print "same"; } else { print "different"; }

  1. same

  2. different

  3. the code is ill-formed

  4. None of the above

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

In Perl, numbers starting with 0 are treated as octal literals. Thus 0123 equals 83 in decimal (1*64 + 2*8 + 3*1 = 83), while 123 is decimal 123. Since 83 != 123, the else branch executes, printing 'different'. This is a classic trap involving Perl's octal notation for numeric literals.