in reply to Re^9: Using a sting with a variable name
in thread Using a sting with a variable name

So why bother using use strict; if it doesn't matter whether a variable exists or not. That perl doesn't care says nothing about whether the programmer cares or not.

Note I never said that the OP cares. I even said he might not ("I don't know if that's ok or not."). I'm just outlining the possibilities the OP might be interested in.

Replies are listed 'Best First'.
Re^11: Using a sting with a variable name
by JavaFan (Canon) on May 11, 2009 at 19:07 UTC
    Considering this entire exercise is only going to work with package variables, and we have to disable strict 'refs' for it to work in the first place, I don't really get your remark about use strict;.

    Package variables are Perl4 left overs. The era predating strict. And lexicals. When Perl variables were much more like AWK or Shell.

    And do get your capitalization right when it matters. perl cares, because perl is the implementation. But in the language, Perl, you can use any package variable you want, at any time*, without making any declaration you intent to use the variable.

    *You may, however, be forced to use the fully qualified name.

      I don't really get your remark about use strict;.

      use strict 'vars'; let's the programmer know that a variable they used doesn't exist. The programmer uses the pragma because they wish to know that (i.e. they care to know that).

      Therefore, it's a counterexample to your claims that existence doesn't matter except "in the few edge cases where you can poke into the underlaying implementation" is false.

      And do get your capitalization right when it matters.

      I did. perl "compiles and runs: print $foo;", not "Perl (language!)".

        use strict 'vars'; let's the programmer know that a variable they used doesn't exist.
        Could you first define what you mean by exists in this context? Because:
        package main; use strict 'vars'; say $var; # Error, ($var doesn't "exist"?)
        package main; use strict 'vars'; say $::var; # No error ($::var does "exist"?)
        But that's clearly nonsense as in both snippets, $var and $::var are the same, and a variable cannot both exist and not exist.