Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
As far as I can see there is no need to
a) read in the whole file at once
b) paste the lines together

Your count won't change if you do the counting line by line - which would solve your memory problem. So it would be worth looking at the part of your program that needs the whole file as string to see, whether this could be changed too. If not, there is the proposition about using "tie" already.

Then, you can search for all valid characters at once and use a hash to collect and count them.

This would be a possible solution:

#!/usr/bin/perl -w use strict; use warnings; use diagnostics; use Data::Dumper; my $filename = "dna.txt"; open(my $fh, "<", $filename) || die "could not open $filename: $!\n"; my %bases; my $cnt_errors = 0; while (<$fh>) { # strip spaces s/\s+//ig; # collect results my @results = ($_ =~ /[ACGT]/ig); map { $bases{$_}++ } @results; $cnt_errors += ( length($_) - scalar @results ); } print Dumper(%bases); print "Errors: $cnt_errors\n";

In reply to Re: Request to detect the mistake in a perl script for finding inter-substring distance from a large text file by lune
in thread Request to detect the mistake in a perl script for finding inter-substring distance from a large text file by supriyoch_2008

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 perusing the Monastery: (4)
    As of 2014-07-13 21:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (252 votes), past polls