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

Fwd: `local` on lexicals

Thread Previous | Thread Next
August 10, 2021 12:56
Fwd: `local` on lexicals
Message ID:
Oops, for course replied only to sender.

---------- Forwarded message ---------
From: Matthew Horsfall (alh) <>
Date: Tue, Aug 10, 2021 at 8:54 AM
Subject: Re: `local` on lexicals
To: shmem <>

On Mon, Aug 9, 2021 at 8:03 PM shmem 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";

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

cond inner

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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About