<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2627" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV>So, I ended up writing a little modifier, because the case changed 
slightly. </DIV>
<DIV>&nbsp;</DIV>
<DIV>I want to use $variable&nbsp;to access a hash element such as:</DIV>
<DIV>
<DIV>$hash-&gt;{$variable}
<DIV>*** and ***</DIV>
<DIV>$hash-&gt;{$variable}-&gt;{'value'}</DIV>
<DIV>&nbsp;</DIV>
<DIV>So I wrote the following Modifier called 
lookup:&nbsp;&nbsp;</DIV></DIV></DIV>
<DIV><PRE>$Petal::Hash::MODIFIERS-&gt;{'lookup:'} = sub {
    my $hash = shift;   
    my $args = shift;     
    my @args = split(/\s+/, $args);
    ##the first is the hash name
    my $the_hash = $hash-&gt;fetch ($args[0]);
    my $param    = $hash-&gt;fetch ($args[1]);
    if($args[2])        
    {                       
        return $the_hash-&gt;{$param}-&gt;{$args[2]};
    }
    else
    {
        return $the_hash-&gt;{$param};
    }
};
</PRE></DIV>
<DIV>This is used in the code like:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&lt;span tal:replace="lookup: the_hash variable field_name"&gt;replace 
me&lt;/span&gt;</DIV>
<DIV>&nbsp;</DIV>
<DIV>and it works nicely</DIV>
<DIV>&nbsp;</DIV>
<DIV>I know I have no real validation built in yet, but that aside, any 
comments?</DIV>
<DIV>&nbsp;</DIV>
<DIV>Regards</DIV>
<DIV>&nbsp;</DIV>
<DIV>Simon</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV 
  style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> 
  <A title=simonmcc@nortelnetworks.com 
  href="mailto:simonmcc@nortelnetworks.com">simonmcc@nortelnetworks.com</A> 
  </DIV>
  <DIV style="FONT: 10pt arial"><B>To:</B> <A title=petal@lists.webarch.co.uk 
  href="mailto:petal@lists.webarch.co.uk">Petal Mailing List</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>Sent:</B> Friday, April 29, 2005 1:38 
PM</DIV>
  <DIV style="FONT: 10pt arial"><B>Subject:</B> [Petal] Accessing variable hash 
  elements</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=Arial size=2>Ok, I know this must be a stupid question, I 
  probably just need more caffeine but.....</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>I need to access a variable hash element 
  $user{$group}</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>if I have a Hash as : </FONT></DIV>
  <DIV><FONT face=Arial size=2>my %user = ( name =&gt; 'Simon', group1 =&gt; 
  '1', group3 =&gt; '1') ;</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>and an array like :</FONT></DIV>
  <DIV><FONT face=Arial size=2>my @groups = (qw/group1 group2 group3/ 
  );</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>and I want to do:</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>&lt;td tal:repeat="group groups"&gt;</FONT></DIV>
  <DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; &lt;span tal:content="user 
  group"&gt;is the user in the group&lt;/span&gt;</FONT></DIV>
  <DIV><FONT face=Arial size=2>&lt;/td&gt;</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>I know this last bit is incorrect, but there must 
  be a simple way of accessing&nbsp;$user{$group}</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>Thanks</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>Simon</FONT></DIV></BLOCKQUOTE></BODY></HTML>