O'Reilly logo

Sams Teach Yourself Perl in 21 Days, Second Edition by Rafe Colburn, Laura Lemay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Global Variables and Packages

Variable scope, in general, refers to the availability and existence of a variable in your script. A global scope, then, refers to a variable that is available to all parts of your script and exists as long as your script is running. Local scope, in turn, refers to a variable that has some limited scope and might pop in and out of existence depending on what part of your Perl script is currently executing.

We'll start this chapter with a look at global variables and global scope. In the next section we'll turn to local scope.

The Problem with Globals

Throughout this book, we've been using global variables (and global scope) in most of the examples, with the exception of the occasional local variable in a subroutine. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required