Some programs in Learning Perl 6th ed. do not work with "use 5.014" - why?

I learn Perl with Llama, 6th ed., And some of the programs in the first chapters do not work with "use 5.014," and I'm not sure why. For instance:

#!/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", but with it turned on I get the following 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 “mine” before the first instances of variables, it still does not start, 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 is happening? I know that I can just run it without “using 5.014,” but the cover of the book says it's the 6th edition. "covers Perl 5.14," so I'm puzzled.

Thank.

+5
source share
3 answers

v5.12, use VERSION , strict. "", , .

Learning Perl , , , . , Perl .

- , , , .

.:)

+13

, use strict, . (, , , , ).

, $sum, , my $sum while, .

my $sum = 0; while, while. sum while, reset , .

+5

use <version>; strict . , -

#!/usr/bin/perl
use 5.014;
my $sum;
my $n=1;

while ($n < 10) {
        $sum += $n;
        $n += 2;
}
print "The total was $sum.\n";
+2
source

All Articles