#!/usr/bin/perl # use strict; use warnings; use 5.010; ##you will print results but first remove any previous files my $cgs = "cg_size.txt"; if (unlink($cgs) == 1) { print "Existing \"cg_size.txt\" file was removed\n"; } #now make a file for the core genome sizes output my $output_cgs = "cg_size.txt"; if (! open(CGS, ">>$output_cgs") ) { print "Cannot open file \"$output_cgs\" to write to!!\n\n"; exit; } my @tests = do { my $randomFile = q{random.txt}; open my $randomFH, q{<}, $randomFile or die qq{open: < $randomFile: $!\n}; map [ split ], <$randomFH>; }; my $columnFile = q{re-organized.txt}; open my $columnFH, q{<}, $columnFile or die qq{open: < $columnFile: $!\n}; my @results; while ( <$columnFH> ) { my @cols = split; foreach my $idx ( 0 .. $#tests ) { foreach my $subidx ( 0 .. $#{ $tests[ $idx ] } ) { my @posns = split m{,}, $tests[ $idx ]->[ $subidx ]; $results[ $idx ]->[ $subidx ] ++ if scalar @posns == grep { q{z} eq $cols[ $_ ] } @posns; } } } close $columnFH or die qq{close: < $columnFile: $!\n}; say CGS qq{@$_} for @results;