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

LanX wrote:
So exporting the whole typeglob will fix it.:).

In case exporter doesn't support * , use your own import

This perfectly does the job!

I replaced

our @EXPORT = qw( %debug $d_area dsay );
by
our @EXPORT = qw( %debug *d_area dsay );
in Dsay.pm.

I now can use

sub one { local $d_area = "one"; dsay "debugging output from one"; } sub two { local $d_area = "two"; dsay "debugging output from two"; } $debug{TWO} = 1; one; two;
and get debugging output from the 'two' area only. Debugging output stops as soon as the localized $d_area value drops out of scope.
And this without the need of qualifying $Dsay::d_area anymore!

Thank you so much! This really helps, and I have learned a lot!

Replies are listed 'Best First'.
Re^3: 'local' for imported variables doesn't work as expected
by LanX (Saint) on Oct 07, 2024 at 21:28 UTC
    > Thank you so much!

    You're very welcome! :)

    > This really helps, and I have learned a lot!

    Great. It's nice to hear that once in a while ... :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery