Mailing List Archive

Fwd: `local` on lexicals
Oops, for course replied only to sender.

---------- Forwarded message ---------
From: Matthew Horsfall (alh) <wolfsage@gmail.com>
Date: Tue, Aug 10, 2021 at 8:54 AM
Subject: Re: `local` on lexicals
To: shmem <gm@qwurx.de>


On Mon, Aug 9, 2021 at 8:03 PM shmem gm@qwurx.de wrote:

A “local my $foo” blurs that difference and introduces a “timely” scoping
for lexicals. Or wouldn’t it? Anyways, aliasing a lexical would need another
metaphor and a different keyword than “local”. Perhaps “alias”?

I don’t understand your concerns here. This is already something you
can basically do:

use strict;
use warnings;

my $x = { x => "outer" };

if (1) {
local $x->{x} = "cond inner";
foo();
}

sub foo {
print "$x->{x}\n";
}

foo();
__END__
cond inner
outer

Why would localizing a scalar $x = 1 be any more confusing than
localizing a slot in an array or hash?

— Matthew Horsfall (alh)