Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Addressing your first issue is simple a matter of incrementing a count rather than printing the line.

$ perl -Mstrict -wE ' > open my $fh, q{<}, \ <<EOD or die $!; > 0 a b h > 1 - r z > 3 u - u > 4 r x r > 5 r t r > 6 r r r > 7 r r r > 8 r r r > EOD > > my $count; > while ( <$fh> ) > { > my( $seq, @cols ) = split; > $count ++ if tr{r}{} == scalar @cols; > } > say $count;' 3 $

The supplementary question requires a little more jiggery-pokery.

$ perl -Mstrict -wE ' > open my $rand, q{<}, \ <<EOD or die $!; > 2 32 321 > 2 13 213 > 3 31 312 > EOD > > my @tests = > map [ split ], > <$rand>; > > open my $fh, q{<}, \ <<EOD or die $!; > 0 a b h > 1 - r z > 3 u - u > 4 r x r > 5 r t r > 6 r r r > 7 r r r > 8 r r r > EOD > > my @results; > while ( <$fh> ) > { > 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{r} eq $cols[ $_ ] } @pos +ns; > } > } > } > > say qq{@$_} for @results;' 4 3 3 4 5 3 5 5 3

I hope this is useful.

Cheers,

JohnGG


In reply to Re^3: Count similar characters in a row by johngg
in thread Count similar characters in a row 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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (7)
    As of 2014-08-30 15:16 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (293 votes), past polls