Multiple choice technology programming languages

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
A Correct answer
Explanation

The == operator performs numeric comparison in Perl, converting strings to numbers. Both '123' and '0123' convert to the number 123 (leading zeros are ignored in numeric conversion). Therefore, $a == $b evaluates to true, printing 'same'.

AI explanation

In Perl, the == operator always performs numeric comparison, so both '123' and '0123' are converted to the number 123 before comparing, making them equal and printing "same". Using eq instead would compare them as strings and correctly report them as different, since leading zeros matter in string comparison but not in numeric comparison.