Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-19 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found