#!/usr/bin/perl use warnings; use strict; # values my @val = qw(0.0 0.2 0.4 0.6 0.8 1.0); my $tiers = 11; # map array indices to values my $m = {}; { my $i = int 0; map { $m->{$i++} = $_ } @val; } # first tier my $p = \@val; # create each additional tier skipping first # that's already in $p for (my $i = 2; $i <= $tiers; $i++) { my $tmp; map { $tmp->[$_] = $p; } keys %{$m}; $p = $tmp; } # output file open(my $outfile, '>', '/tmp/output.txt') or die $!; # use recursion to decend the huge matrix # build up the string at each tier my $fn; $fn = sub { my ($aref, $str) = @_; for (my $i = int 0; $i < @{$aref}; $i++) { if(ref($aref->[$i])) { $fn->($aref->[$i], $str."\t".$val[$i]); next; } # end of the line, print last tier of values print $outfile $str."\t".$_."\t1\t1\n" for @val; last; } }; # kick off the recursion, could do these in parallel # at the top-most layer for (my $i = int 0; $i < @{$p}; $i++) { $fn->($p->[$i], $val[$i]); }