in reply to Re: 'local' for imported variables doesn't work as expected (4 updates)
in thread 'local' for imported variables doesn't work as expected

The reasons for this are unclear to me

In the hash case, local replaces the SV in one hash. You then access the SV via the same hash.

In the scalar case, local replaces the SV in one package. You then access the SV found in a different package.

Replies are listed 'Best First'.
Re^3: 'local' for imported variables doesn't work as expected [4 updates]
by ikegami (Patriarch) on Oct 04, 2024 at 14:52 UTC

    Proof that it works the same for scalars in hashes as with scalars in packages:

    $mod::d_area = "(default)"; *d_area = \$mod::d_area; # Create alias in *main:: { local $d_area = "one"; # Replace scalar say $mod::d_area; # (default) $mod::d_area = "two"; say $d_area; # one } say $d_area; # two
    my %mod = ( d_area => "(default)" ); my %main; \$main{ d_area } = \$mod{ d_area }; # Create alias in %main { local $main{ d_area } = "one"; # Replace scalar say $mod{ d_area }; # (default) $mod{ d_area } = "two"; say $main{ d_area }; # one } say $main{ d_area }; # two