in reply to Graph model problem.

kyle has given you a very informative response which will hopefully move you onwards. I have a couple of comments about some of your code which may help you in the future, or at least save you some typing. Some consider it good practice to distinguish scalars holding simple values from those holding references to other data types, e.g. $ref_to_array_of_colours = ['red', 'blue', 'green];. I seem to be in a minority in preferring to use camel-case notation and would use the more succinct $raColours; I would use $rhWhatever for a hash reference, $rsThing for scalar ref. etc. I follow this scheme in my suggestions below.

This section of your code

my $couldy=['cloudy','t','f']; # 'cloudy' is the node name and 't','f' + are the values this node can assume. Likewise for other nodes. my $sprinkler=['sprinkler','t','f']; my $rain=['rain','t','f']; my $wetgrass=['wetgrass','t','f']; my $values=[$sprinkler,$couldy,$rain,$wetgrass];

Could be re-written without the intermediate variables as you don't seem to use them again.

my $raValueSets = [ ['cloudy', 't', 'f'], ['sprinkler', 't', 'f'], ['rain', 't', 'f'], ['wetgrass', 't', 'f'], ];

Passing arguments to sub cpt { ... }, I would tend to keep the anonymous arrays as they are and de-reference them later, like this

sub cpt { my ($node, $raParents, $raNodeValues) = @_; ... foreach my $i ( @$raParents ) { for my $j ( 0 .. $#$raNodeValues ) { if ( $i eq $raNodeValues->[$j]->[0] ) { push @nodeindex, $j; } } } ... }

Note that I use the -> de-reference operator rather than the ${$x}[n] notation, which can quickly become unreadable. In sub parentchildrelationship { ... } you do my $node=$_[0]; #or use "shift" but you can also do

my ($node) = @_;

which puts the LHS in list context and assigns the first element of @_ to the first element of that list, namely $node. Actually, I tend to use shift.

I hope these points are of interest.

Cheers,

JohnGG