I'm learning Perl with the Llama, 6th ed., and some of the programs in the first chapters don't work with "use 5.014", and I'm not sure why. For example:
#!/usr/bin/perl
#use 5.014;
$n = 1;
while ($n < 10) {
$sum += $n;
$n += 2;
}
print "The total was $sum.\n";
This works with "use 5.014" commented out, but with it included, I get these errors:
Global symbol "$n" requires explicit package name at ch3loop.pl line 5.
Global symbol "$n" requires explicit package name at ch3loop.pl line 6.
Global symbol "$sum" requires explicit package name at ch3loop.pl line 7.
Global symbol "$n" requires explicit package name at ch3loop.pl line 7.
Global symbol "$n" requires explicit package name at ch3loop.pl line 8.
Global symbol "$sum" requires explicit package name at ch3loop.pl line 10.
Execution of ch3loop.pl aborted due to compilation errors.
However, if I put "my" before the first instances of the variables, it still doesn't run, but for a different reason:
Global symbol "$sum" requires explicit package name at ch3loop.pl line 10.
Execution of ch3loop.pl aborted due to compilation errors.
Can someone explain what's going on? I know I can just run this without "use 5.014", but it does say on the cover of the book that the 6th ed. "covers Perl 5.14", so I'm puzzled.
Thanks.