It’s important to remember that in Perl all scalar variables have an initial value of the null string, “”. You do not need to define a value for scalar variables unless you are using “strict” mode. Knowing this, what do you think the output of the below code will be?
Since the variable “$undefined_var” is undefined, the Perl interpreter assigns the null string default value. Because the null string is being used in an addition operation, Perl converts the null string to 0 and adds it to 5; the result is stored in the variable $result.
Blog Archives
Search Blog Archives