http://qs321.pair.com?node_id=11135932

misterperl has asked for the wisdom of the Perl Monks concerning the following question:

I want to use the same name for a var above and inside braces, but in some cases, I want to make a local copy to use in the braces:
# sorta like my $self = new OO( $cat ); { my $self = new OO( $dog ) if $ARGV[0] eq 'Fido'; say $self->species(); }
.. but at the "say" line, self is undef when ARGV[0] ne 'Fido'; Which surprised me, since I thought OK- it wont create a new scope of $self in the braces, so the scope above should persist? I also tried ( my $self = new OO( $dog ) ) if $ARGV[0] eq 'Fido'; which I thought had an even better chance to succeed but didn't.

Seems counter-intuitive that ANY part inside of ( ) would have any influence, if followed by "if 0"?

When I emerge from the braces I want the original self there, and I dont want to use another variable name since I have hundreds of "self" refs in the braces... I also tried "local" instead of "my" but got a lexical error in that case.

TY