This section describes how a scalar value will be interpreted in an operation. A tutorial example is provided to verify scalar value interpretation rules.
When a scalar value is used in an operation, it could be interpreted in three
ways depending on the type of value the operation is expecting:
A scalar value will be interpreted as a number, if the operation is expecting a numeric value.
If the scalar value is a numeric value, Perl will take it as is.
If the scalar value is a string value, Perl will try to parse it into a number. If parsing failed,
it will be interpreted as 0.
A scalar value will be interpreted as a string, if the operation is expecting a string value.
If the scalar value is a string value, Perl will take it as is.
If the scalar value is a numeric value, Perl will convert it into a string representation of that value.
A scalar value will be interpreted as TRUE or FALSE, if the operation is expecting a Boolean value.
Perl will interpret number 0, string '0', and empty string '' as FALSE. Any other values will be interpreted as TRUE.
To verify the rules listed above, I wrote the following Perl tutorial script: