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

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.

Replies are listed 'Best First'.
Re^12: Using a sting with a variable name
by ikegami (Patriarch) on May 11, 2009 at 20:01 UTC

    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.

        Could you first define what you mean by exists in this context?

        You're asking the wrong person. I'm trying to satisfy the OP, and like I said before, his question was a bit vague. Perhaps he would like to know if there's exists a given variable in the program. (That can be determined by peeking at the symtab, with the caveat I previously mentioned.)