in reply to Re^5: use has it's own scope?
in thread use has it's own scope?

Actually, I agree with you -- I didn't say I would be the one to make that argument ;-)

Maybe I should have suggested that it could arguably be a warning. Perl warns on all kinds of things that are valid but "potentially confusing," and there seems to be a fair amount of back-and-forth about what those things are.

Replies are listed 'Best First'.
Re^7: use has it's own scope?
by chromatic (Archbishop) on Aug 08, 2017 at 16:48 UTC

    Yeah, I see the argument for making it a warning.

    Detecting this case is complicated, though. Unlike pseudo-state variables, it's not a shaky part of syntax and composition and implementation. At best, you might be able to express that a lexical variable appears to be used only once, but I can still imagine a bizarre module interface which closes over the using scope's lexical.

      I can still imagine a bizarre module interface which closes over the using scope's lexical

      I can, too; but I tried, and I don't think it can be done -- at least not without resorting to something in the B namespace. You could probably do it, though. ;-)

      I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.

        Doesn't keeping the elements in @_ basically have the same effect since they are aliases to the values in the use statement?

        package Set; sub import { our $var = \$_[1]; } 1;
        With this module, perl -e "use Set (my $x = 6,); $$Set::var++; will work but perl -e "use Set (6,); $$Set::var++;

        will fail because "Modification of a read-only value attempted at -e line 1."

        > resorting to something in the B namespace.

        That's my plan ... ;)

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!