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


In reply to Re: Graph model problem. by johngg
in thread Graph model problem. by newbio

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.