#!/usr/bin/perl #use strict; #use warnings; use integer; use Math::Matrix; ##you will print results but first remove any previous files my $fcgs = "final_cg_size.txt"; if (unlink($fcgs) == 1) { print "Existing \"final_cg_size.txt\" file was removed\n"; } #now make a file for the final core genome sizes output my $output_fcgs = "final_cg_size.txt"; if (! open(FCGS, ">>$output_fcgs") ) { print "Cannot open file \"$output_fcgs\" to write to!!\n\n"; exit; } open IN, 'cg_size.txt' or die$!; my @colSum; while(){ chomp($_); our @array =(); our @colArray = split(/\s/,$_); for(my $i = 0; $i <= $#colArray; $i++){ $colSum[$i] += int($colArray[$i]); } for(our $i = 0; $i <= $#colArray; $i++){ $error_bars[$i] = $colArray[$i]; } my $sorted = sortSub(@colArray, 0, 1, 3); # print "$error_bars[16] \n"; # prints elements of column 16 # print "@error_bars \n"; # not what I want print "***************************\n"; } print "\n"; foreach my $ j(0 .. $#colSum){ print "The sum of column",$j+1," is: ",$colSum[$j],"\n"; } sub sortSub { my @array = @{ +shift }; my @sorted = sort { for my $ix ( @_ ) { my $cmp = $a->[$ix] <=> $b->[$ix]; return $cmp if $cmp; } return 0; } @array; return \@sorted; } _FILE_ 2124 1827 1702 1710 1658 1637 1676 1630 1602 1607 1579 1558 1575 1550 1548 1540 1537 2058 1771 1776 1701 1645 1672 1615 1599 1609 1583 1570 1587 1578 1563 1555 1541 1537 2237 1864 1684 1673 1633 1667 1610 1624 1591 1589 1593 1576 1565 1570 1559 1539 1537 2056 1845 1748 1693 1679 1670 1663 1638 1590 1564 1564 1573 1571 1545 1542 1543 1537 2056 1808 1755 1689 1684 1663 1627 1581 1594 1580 1580 1616 1559 1568 1541 1539 1537 1957 1889 1769 1667 1697 1669 1637 1631 1584 1621 1576 1570 1569 1552 1547 1542 1537 2181 1991 1706 1715 1654 1686 1605 1622 1594 1597 1576 1564 1567 1560 1567 1540 1537 2056 1873 1803 1711 1715 1669 1630 1619 1578 1604 1584 1568 1557 1556 1544 1549 1537 1996 1915 1746 1690 1685 1630 1625 1589 1609 1593 1569 1562 1574 1555 1548 1541 1537 2181 1875 1810 1728 1638 1625 1628 1621 1614 1587 1576 1558 1552 1557 1543 1541 1537