in reply to Re^3: Short invocation for per-object methods
in thread Short invocation for per-object methods

my provides static binding.
local our provides dynamic binding.

Both have their uses. The latter would allow me to set $Carp::Verbose for just one call to carp, for example.

{ local $Carp::Verbose = 1; carp(...); }

(Mind you, not a good example, since I could just have called croak.)

And just to show that it works:

sub bar { print our $var, "\n"; # Prints 2 } sub foo { local our $var = 2; bar(); } our $var = 1; foo();

Replies are listed 'Best First'.
Re^5: Short invocation for per-object methods
by perrin (Chancellor) on Jan 04, 2007 at 16:47 UTC
    I use it for file slurping (local $/) and for DBI (local $dbh->{'AutoCommit'}). The latter looks strange, but works because of the way DBI is implemented, and makes AutoCommit automatically snap back to its old value when I leave the current scope.