in reply to 'local' for imported variables doesn't work as expected
I ran a quick test on my mobile, and this works for me.
Probably an issue with Exporter ?
use v5.12; use warnings; BEGIN{ package log; our $var= "default"; sub tst { say $var } # export *::var = *var; *::tst = *tst; } package main; our $var; { local $var = "foo"; tst(); } tst();
perl local_import_var.pl foo default
Anyway I'd rather recommend another design, like using caller to get the function's name or setting a regex to parse the message for keywords.
HTH :)
AHH, got it. What exporter does is to only export the scalar slot, which is causing your problem.
*::var = \$var; # replace!
Effect:
perl local_import_var.pl default default
So exporting the whole typeglob will fix it.:).
In case exporter doesn't support * , use your own import
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: 'local' for imported variables doesn't work as expected
by muthm (Sexton) on Oct 06, 2024 at 22:28 UTC | |
by LanX (Saint) on Oct 07, 2024 at 21:28 UTC |