[sf-perl] Make a hash key's value dependent on the key itself?

cataldo cataldo at boutell.com
Sat Jul 1 20:27:40 PDT 2006


Would it be easier to create a class that knows what you want?

$target = $hosts->rsync_target($hostname);
and quickly code in your own magic?


-stephen



Stephen Cataldo
SpaceShare.com
6420 Colby St.
Oakland, CA 94618
(510) 520-6175

Replacing Cars with Community:
Interested in learning more about SpaceShare? Join our monthly 
newsletter list: www.spaceshare.com/email_newsletter



but I suppose procrastination is False Laziness.

David Alban wrote:

>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
>  
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20060701/1ebe30e8/attachment.html 


More information about the SanFrancisco-pm mailing list