$hd::size1 = scalar @{\@{$main::M[0]}}; $hd::size = $hd::size1 - 1; for ($hd::i=$hd::save; $hd::i<= $hd::size; $hd::i++) #this creates and adds to the hd array { $hd::store= []; for ($hd::j=0; $hd::j < $hd::i; $hd::j++) { $hd::temp = &hd($main::M[0][$hd::i], $main::M[0][$hd::j]); print $hd::temp; print "\n"; push $hd::store, $hd::temp; } push @{$main::hd}, $hd::store; } $hd::save = $hd::size #### #!/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]; $main::hdt = 0.4; $main::c = []; $main::c1 = 1; $main::c2 = 0.75; $main::c3 = 0.75; #how to add elements to an array push $main::c, $main::c1; push $main::c, $main::c2; push $main::c, $main::c3; #how to add arrays to arrays push @{$main::hd}, $main::a; push @{$main::hd}, $main::b; push @{$main::hd}, $main::c; &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); }