So I'm using a module that requires an lower diagonal matrix. However, there seems to be some importance on how the matrix is defined. If I were to define the matrix like this
$distmatrix=[[] , [0.25], [0.25,0.5], [1,0.75,0.75]]
Everything works fine, however, when I define a matrix like this
$main::hd=[[]]; $main::a = [0.25]; $main::b = [0.25,0.5]; $main::c = [1,0.75,0.75]; push @{main::hd}, [@main::a]; push @{main::hd}, [@main::b]; push @{main::hd}, [@main::c];
then I have an error. Whats the difference between the two? I need to add to my distance matrix every time step as it grows, so defining the distance matrix explicitly doensn't look like an option.

EDIT

I'm still at school, but I'll try your suggestions when I get home. The code I'm using does have strict on, but the error is with two modules that I'm using, or rather, the input I'm giving the module isn't what it expects (evidenced by a croak statement) When I run the following code
#!/usr/bin/perl #ex2 use warnings; use strict; sub clust; $main::hd=[[]]; $main::a = [0.25]; $main::b = [0.25,0.5]; $main::c = [1,0.75,0.75]; push @{main::hd}, [@main::a]; push @{main::hd}, [@main::b]; push @{main::hd}, [@main::c]; $main::hdt = 0.4; &clust; for ($loop::i=0; $loop::i<=3; $loop::i++) { print $clust::cluster_ids->[$loop::i], "\n"; } sub clust { use Algorithm::Cluster::Thresh; use Algorithm::Cluster qw/treecluster/; $clust::tree = treecluster(data=>$main::hd, method=>'a'); $clust::cluster_ids = $clust::tree->cutthresh($main::hdt); }
I get the error "memory allocation failure in treecluster" Which, after I read the module code comes from a croak statement if "!distmatrix" which I'm guessing means that if I input something that's not the correct kind of matrix, then it can't work. However, If I use the code
#!/usr/bin/perl #ex2 use warnings; use strict; sub clust; $main::hd=[[] , [0.25], [0.25,0.5], [1,0.75,0.75]]; $main::hdt = 0.4; &clust; for ($loop::i=0; $loop::i<=3; $loop::i++) { print $clust::cluster_ids->[$loop::i], "\n"; } sub clust { use Algorithm::Cluster::Thresh; use Algorithm::Cluster qw/treecluster/; $clust::tree = treecluster(data=>$main::hd, method=>'a'); $clust::cluster_ids = $clust::tree->cutthresh($main::hdt); }
I get the desired output
1 1 1 0
Sorry for being so vague, and I'll try your solutions tonight when I get home.

In reply to Arrays and Push by viored

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.