%nodes=( root => { parents => [], probs => [0.01]}, # P(root) some => { parents => ['n1'], probs => [0.74,0.21]}, # P(some|!root), P(some|root) other =>{ parents => ['root','n1'], probs => [0.12,0.24, # P(other|!root,!some), P(other|!root,some) 0.81,0.18]}, # P(other|root,!some), P(other|root,some) ); #### # the state you start from %state=(root=>1,some=>0); # let's get P(other|root,!some) $i=0; for @{$nodes{other}{parents}} { $i=($i<<2)+$state{$_} # this is a simple encoding. Just use the same for updating and accessing } $prob=$nodes{other}{probs}[$i]; #### use XML::Simple; print XMLout(\%nodes);