Local Scope and Variables

A local variable, as you learned on Day 11, “Creating and Using Subroutines,” is one that is only available to a certain part of a script. After that part of the script is finished executing, the variable ceases to exist. Local variables also have a limited availability to other parts of a script. They might be private to just the scope in which they were defined, or they might only be available to those parts of the script that are running at the same time as the part of the script that defined the variable.

Local Variables and Local Scope

On Day 11, we looked at local variables, defined with my, inside subroutines. A subroutine defines a local scope, and the local variable is available to all the code defined inside ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.