http://qs1969.pair.com?node_id=11135948


in reply to Not sure how to handle this scope

In this respect, lexical variables are much like local. The new variable is not initialized.
use strict; use warnings; use feature 'say'; package OO; sub new {my $animal = $_[1]; return bless \$animal;} sub species { return ${$_[0]} } package main; my $cat = 'cat'; my $dog = 'dog'; my $self = new OO( $cat ); { my $self = $self; $self = new OO( $dog ) if $ARGV[0] eq 'Fido'; say $self->species(); } say $self->species();

OUTPUT (with argument 'Fido')

dog cat

OUTPUT (without argument 'Fido')

cat cat
Bill