in reply to How do I get the value of a number that is part of a string?
you'll get 3. If you say:my $x = "1"; my $y = "2"; print $x + $y, "\n";
you'll get 12 ("2" appended to "1"). To force interpretation in a numeric context, you can try:my $x = "1"; my $y = "2"; print $x . $y, "\n";
and you'll get 10. Note that this only works on scalars starting with digits. Strip them out with a regex if you need to.my $x = "10abc"; print $x + 0, "\n";
|
|---|