[sf-perl] Make a hash key's value dependent on the key itself?
David Alban
extasia at extasia.org
Sat Jul 1 18:42:22 PDT 2006
Greetings,
Say I want to do something like:
$hosts => {
foo => {
source_tree => '/some/dir',
rsync_target => "bat:$spool_dir/foo/",
},
bar => {
source_tree => '/some/other/dir',
rsync_target => "bat:$spool_dir/bar/",
},
.
.
.
};
But I don't want to hardcode hostnames "foo" and "bar" in the
rsync_target values. Is there a way to do something like:
$hosts => {
foo => {
source_tree => '/some/dir',
rsync_target => "bat:$spool_dir/" . __KEY__ . '/',
},
bar => {
source_tree => '/some/other/dir',
rsync_target => "bat:$spool_dir/" . __KEY__ . '/',
},
.
.
.
};
That is, is there some magic string I can put in the source to
indicate to the compiler to use the value of the current hash key?
Of course, I just noticed that this ability would have to allow the
coder to specify out to what level the magic string referred. 'Cause
in my example, I wouldn't want the value substituted for __KEY__ to be
the string 'rsync_target'. :-)
Thanks,
David
--
Live in a world of your own, but always welcome visitors.
More information about the SanFrancisco-pm
mailing list