And when you *do* start using strict, it won't let you use symbolic (soft) references anyway. | [reply] |
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?
| [reply] |
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.
| [reply] |
Use a hash and don't abuse globals just to pass arguments. to paraphrase your code:
#!/usr/bin/perl -w
use strict;
check(qw(a b c));
sub check {
my %hash = (
a => 'here',
b => 'present',
c => 'me too',
);
for (@_) {
print "$hash{$_} has a value\n";
}
}
| [reply] [d/l] |
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.
| [reply] |