Having looked over your code, I think I found your problem, and I have a few other comments.

The only substantial change I made was the assignment to @nodevalues in the cpt sub. It now reads:

my @nodevalues= map { [ @{$_} ] } @{$_[2]};

The reason why that helps is that $_[2] is a reference to an array containing other array references. What my change does is copy the arrays in the main array instead of copying the references. This is important because further down in your code, you do "shift @{$temparray[$i]};", which modifies one of those arrays. Without my modification, here is what happens. Before the first call to cpt, this is what $values looks like:

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

After the first call to cpt, it looks like this:

$VAR1 = [ [ 't', 'f' ], [ 't', 'f' ], [ 'rain', 't', 'f' ], [ 'wetgrass', 't', 'f' ] ];

Notice that the first two arrays have been modified. The above is the output of Data::Dumper, by the way. It's a pretty good way of visualizing your data structures.

The fix I've shown will help this particular problem, but it would not have helped if the data structure involved were another level deep. For a more general solution to this kind of problem have a look at merlyn's column Deep copying, not Deep secrets.

My other comments, briefly:


In reply to Re: Graph model problem. by kyle
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.