You can use ddumperBasic debugging checklist to visualize the data structure you have (lesson courtesy of Basic debugging checklist and brian's Guide to Solving Any Perl Problem )

If I do that I see that the first row is indeed empty [[], [0.25], [0.25, 0.5], [1, 0.75, 0.75]];

Try to follow https://metacpan.org/source/MDEHOON/Algorithm-Cluster-1.52/perl/examples/ex5_treecluster

This is how you should write that, pass arguments (often references to arrays), return values, meaningful names

This is your code cleaned up, some comments, but the data unfixed (I would use ex5_treecluster data as starting point )

#!/usr/bin/perl -- #~ clust-brain.pl #~ 2014-04-06-15:43:25 #~ #~ perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; Main( @ARGV ); exit( 0 ); sub Main { ## compact notation ## first stored in an arrayref # my $hd = [[], [0.25], [0.25, 0.5], [1, 0.75, 0.75]]; ## then stored in a named array # my @the_hd = ([], [0.25], [0.25, 0.5], [1, 0.75, 0.75]); ## same thing more verbose notation ## array ref first my $hd_arrayref; $hd_arrayref->[1][0] = 0.25; #d1 $hd_arrayref->[2][0] = 0.25; #d1 $hd_arrayref->[2][1] = 0.5; #d1 $hd_arrayref->[3][0] = 1; #d1 $hd_arrayref->[3][1] = 0.75; #d1 $hd_arrayref->[3][2] = 0.75; #d1 ## named array second my @hd_array; $hd_array[1][0] = 0.25; #d1 $hd_array[2][0] = 0.25; #d1 $hd_array[2][1] = 0.5; #d1 $hd_array[3][0] = 1; #d1 $hd_array[3][1] = 0.75; #d1 $hd_array[3][2] = 0.75; #d1 ## putting values in an array ref without loops # my $cluster_ids = ( 0, 1, 2, 3 ); # my $cluster_ids = [ 0 .. 3 ]; my $hdt = 0.4; ## call clust_brain() function ... no need for short names #~ my $cluster_ids = clust_brain( $hd_arrayref, $hdt ); my $cluster_ids = clust_brain( \@hd_array, $hdt ); ## because we "import"ed dd from Data::Dump we don't have to type full + name # Data::Dump::dd( $cluster_ids ); dd( $cluster_ids ); } ## end sub Main sub clust_brain { ## ARGUMENT PASSING, first arg reference, second arg number my( $hd_ref, $some_hdt ) = @_; use Algorithm::Cluster::Thresh; use Algorithm::Cluster qw/treecluster/; ## you my $varname ONCE to make it my $tree = treecluster( data => $hd_ref, method => 'a' ); ## then you call method cutthresh on $varname with argument my $var_i_call_cluster_ids_also = $tree->cutthresh( $some_hdt ); ## you return the value return $var_i_call_cluster_ids_also; } ## end sub clust_brain __END__

In reply to Re: Array storage issue by Anonymous Monk
in thread Array storage issue 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.