#!/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__