Dear Monks,

I have been using a script that you helped develop:

http://perlmonks.org/index.pl?node_id=864169

The script has been brilliant. However, I am faced with a new task. The script has been counting all the rows that have all columns with exactly the same characters in my data. The data file is here:

http://perlmonks.org/index.pl?abspart=1;displaytype=displaycode;node_id=864179;part=4

This was done in a random fashion using the file:

http://perlmonks.orgindex.pl?abspart=1;displaytype=displaycode;node_id=864179;part=3

How do I modify the script to count the row only once once it has counted a previous row with the same integer/number in that appears infront of my row characters (that is the z's)?

The script I am using current is below. It takes the random file as: "random.txt" and the data file as "re-organized.txt"

jgg.pl

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

In reply to Count similar characters in a row - only once by $new_guy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.