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

If you had actually read the original post, you might have noticed that the OP did, in fact, create a module called set.pm. The syntax use set my $y =666; is actually valid, but it's also useless because $y goes out of scope immediately. Arguably it should be disallowed, but nobody cares.

Replies are listed 'Best First'.
Re^5: use has it's own scope?
by chromatic (Archbishop) on Aug 08, 2017 at 15:52 UTC
    Arguably it should be disallowed

    Why? LIST here is the standard argument passing mechanism. Making an exception for a my expression in an argument list or making an exception for expressions in import lists would be complicated and break symmetry of syntax, semantics, and implementation.

    This is the piece that sundial's missing. It's a confusing combination of existing Perl behavior because it's uncommon and relatively useless, but it's valid syntax because of the way Perl works.

      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.

        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.