I am new to perl, and have been trying to learn out of a book. I am using Komodo to run the scripts.
I am trying to create variables, but instead of coding what the book has put
$x=4;
I have to write
my $x=4;
Or else I get the following error
Global symbol "$x" requires explicit package name
Why is this? Can I change it at all?
You can get rid of that requirement by not using
use strict;
, I've no idea if you are seeing the error because you haveuse strict
or because Komodo is adding it for you.That said, however, do use
use strict;
. It catches all sorts of issues.The book appears to be teaching you Perl 4 era coding practices. Perl 5 was released in 1994! Get a better book (such as Modern Perl or Learning Perl, 6th edition)!