develooper Front page | perl.perl5.porters | Postings from August 2021

Fwd: `local` on lexicals

Thread Previous | Thread Next
From:
wolfsage
Date:
August 10, 2021 12:56
Subject:
Fwd: `local` on lexicals
Message ID:
CAJ0K8bi4c5Yb=5nh+Wn4uNYTU5h6oZGOigXvwNZm0L_pGsf=-Q@mail.gmail.com
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)

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About