Chapter 4. Statements and Declarations
A Perl program consists of a sequence of declarations and statements. A declaration may be placed anywhere a statement may be placed, but its primary effect occurs at compile time. A few declarations do double duty as ordinary statements, but most are totally transparent at run time. After compilation, the main sequence of statements is executed just once.
Unlike many programming languages, Perl doesn't require
variables to be explicitly declared; they spring into existence upon
their first use, whether you've declared them or not. If you try to use
a value from a variable that's never had a value assigned to it, it's
quietly treated as 0 when used as a number, as ""
(the null string) when used as a string, or simply as false when used as
a logical value. If you prefer to be warned about using undefined values
as though they were real strings or numbers, or even to treat doing so
as an error, the use warnings declaration will take
care of that; see the section Section 4.9 at the end of this
chapter.
You may declare your variables
though, if you like, using either my or
our in front of the variable name. You can even make
it an error to use an undeclared variable. This kind of discipline is
fine, but you have to declare that you want the discipline. Normally,
Perl minds its own business about your programming habits, but under the
use strict declaration, the use of undeclared
variables is apprehended at compile time. Again, see Section 4.9 ...