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.
Perl – Initial Values and Context Based Evaluation
This entry was posted in Perl, Programming Languages, Technology and tagged context based evaluation, null string, perl, perl default value, perl default variable value, scalar variable, scalar variables, undefined variable. Bookmark the permalink.