in reply to Re^2: REGEX Match Single Digit
in thread REGEX Match Single Digit

One of the things I love about Perl is the weak typing on scalars. The digit 1 and the string "1" have roughly equivalent internal representations and which one is used depends upon the context of your call. For example the line

print "1 line of text" + 1;

will output the string "2". You start with a string and a number combined with the + operator. That operator takes two numbers as arguments, so perl attempts to convert the string to a number - this truncates from the first non-numeric character. We then evaluate 1+1 = 2. That two is then passed to the print subroutine, which takes a string input. Therefore, 2 is converted to "2" and output to STDOUT. Coming from a strongly-typed background, that still fills me with a profound warmth every time I do it.