in reply to local our?

our is a compile-time declaration for package variables like my for private variables.

our is lexically aliasing $bob to $PKG::bob (the "fully qualified name")

"Lexically" means here till the end of the surrounding scope

PKG is the current package name, i.e. main by default.

It's important to understand that the variable is global and won't be destroyed at the end of the scope, like with private my-variables. Only the alias is disappearing.

local is a runtime directive to save the variables value and restore it at the end of the scope. local is the builtin mechanism to avoid global consequences to package vars. (Perl4 didn't have private my-vars, and unfortunately one "can't localize lexical variable" ³)

> Where and why would I use

You can write our $bob multiple times to avoid the need to write $PKG::bob inside dedicated scopes. But it won't create a new local variable like my does.

local our $bob = 'bob'; will protect the old value from being overwritten by "bob".

It's a shortcut for writing 2 statements our $bob;local $bob ="bob"; *)

use strict; use warnings; use Data::Dump qw/pp dd/; $main::bob = "by"; # fully qualified global var warn "$main::bob\n"; # > by { our $bob = "tail"; # lexical alias warn "$bob\n"; # > tail } warn "$main::bob\n"; # > tail # warn "$bob\n"; # ERR: Global symbol "$bob" requires explicit package name { local our $bob = "bob"; # protect from global effects warn "$bob\n"; # > bob package OTHER; warn "$bob\n"; # > bob (still aliased to $main::b +ob ²) } warn "$main::bob\n"; # > tail

So yes, there are circumstances where it's pretty useful to write local our $var

HTH! =)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

UPDATE
*) logical error corrected, thanks to choroba to notice the glitch.

²) This demonstrates an essential often ignored difference to "use vars ;"

³) it's unfortunate that "lexical var" is synonymously used for "private var", since like demonstrated, our has a lexical effect.