Um...I just wrote twisted routine to handle a bunch of symbolic references. This is a code snippet where I pass in the name of a variable, and use it to construct 3 different symbolic variable names that seem to all work (the variables are 'package' variables declared using 'our'. How is this different?
AH... just verified: Our vs. my.
sub _common_setvar {
my $XX = shift; # XX=(db|cache)
no strict 'refs';
my $XX_prefix = $XX . '_prefix';
debug("path_ops","_XX_prefix=%s",$XX_prefix);
if (@_) {
$$XX_prefix = $_[0];
my $_XX_prefix_set = "_" . $XX_prefix . "_set";
debug("path_ops","_XX_prefix_set=%s",$_XX_prefix_set);
$$_XX_prefix_set = True;
my $_save_XX_prefix = '_save' . $$XX_prefix;
if ($_storage_dir_set) {
my $tmp =
$$_save_XX_prefix = _path_cat($storage_dir,$$XX_prefix);
debugn("path_ops",
"cmn_sv: sd=%s, ddXX_p=%s, ddsave_XX_p=%s, ",
$storage_dir, $tmp, $$XX_prefix);
_dir_check($$_save_XX_prefix);
}
}
$$XX_prefix;
}
sub db_prefix {
my $this=shift;
_common_setvar('db',@_);
debug("path_ops","db=%s, sdb=%s",$db_prefix,$_save_db_prefix);
}
sub cache_prefix {
my $this=shift;
_common_setvar('cache',@_);
debug("path_ops","cache=%s, scache=%s",$cache_prefix,$_save_cache_
+prefix);
}
|