use strict;
use warnings;
my $x = "2abc";
my $y = $x + 42;
print "x=", $x, " y=", $y, "\n";
####
Argument "2abc" isn't numeric in addition (+) at f.pl line 4.
x=2abc y=44
##
##
x = "2abc"
y = x + 42
print "x=", x, "y=", y, "\n"
##
##
Traceback (most recent call last):
File "f.py", line 2, in
y = x + 42
TypeError: cannot concatenate 'str' and 'int' objects
##
##
x = "2abc"
y = int(x) + 42
print "x=", x, "y=", y, "\n"
##
##
Traceback (most recent call last):
File "f2.py", line 2, in
y = int(x) + 42
ValueError: invalid literal for int() with base 10: '2abc'
##
##
x = "2abc"
y = int(x[0:1]) + 42
print "x=", x, "y=", y, "\n"
##
##
x= 2abc y= 44
##
##
x = "2abc"
y = x + 42
print "x=", x, "y=", y, "\n"
##
##
f.rb:2:in `+': can't convert Fixnum into String (TypeError)
from f.rb:2
##
##
x = "2abc"
y = x.to_i() + 42
print "x=", x, " y=", y, "\n"
##
##
x=2abc y=44