in reply to Re: when is "my" not necessary?
in thread when is "my" not necessary?

OK.. This is driving me crazy. In package x, I have @list = ('a','b','c'). In package y, (after requiring package x), I try: my($a,$b,$c)=(); $a = 'Here'; $b = 'Present': $c = 'Me too'; for(@x::list){ if ($$_) {print "$_ has a value"} } but this does not work using 'my'. I too have moved to stict to support mod_perl (what an excercise!). Why do I do this? I collect form variables (stored in $a,$b,$c) but if they are in @a::list (or better yet, a comma separated database column), they are user-required (and display an error to user if missing). Is this a bad use for symbolic references? What would you do?

Replies are listed 'Best First'.
Re^3: when is "my" not necessary?
by bart (Canon) on Nov 06, 2004 at 17:56 UTC
    Storing form variables in global variables feels like a very bad idea to me, for the same reason any unrestricted set of global variables is a bad idea.

    Personally I prefer a hash to store the form variables in, CGI.pm does support it, though its a rather new feature, and it's rather well hidden. Look up the method Vars.

Re^3: when is "my" not necessary?
by Joost (Canon) on Nov 04, 2004 at 18:52 UTC
      Thanks... ephiphony moment. I'm convinced to use strict refs and eliminate any symbolic usage.

      package x actually is a static cache of prefs stored in a database refreshed only when those prefers are updated by a user.

      Doing my stunt (above), I'm now using a hash to store all form fields and simply checking presence using the x list for that preference.

      Thanks-Thanks.