<?xml version="1.0" encoding="windows-1252"?>
<node id="949618" title="Request to detect the mistake in a perl script for finding inter-substring distance from a large text file" created="2012-01-24 04:39:09" updated="2012-01-24 04:39:09">
<type id="115">
perlquestion</type>
<author id="942579">
supriyoch_2008</author>
<data>
<field name="doctext">
&lt;p&gt;Hi Perl Monks,&lt;/p&gt;
&lt;P&gt;I am a beginner in perl programming. I have written a perl script which can read a small text file and gives correct results for inter-substring distance in cmd in Windows XP. But cmd shows the problem of “out of memory” when I try to analyze a large text file with 219475005 letters for finding the inter-substring  distance although the program counts the number of each letter in the file correctly within 2 minutes but fails to find the inter-substring distance.  I think this could due to incorrect reading of file.&lt;/p&gt; &lt;p&gt;So  I have given the initial part of the script and the results of cmd screen below. I am seeking your suggestions to rectify the mistake in the script for analyzing a large file. &lt;/p&gt;&lt;p&gt;Furthermore, I need the syntax at the initial part to assign the input large file to an array variable like&lt;code&gt; my @lines &lt;/code&gt;so that I can assign this array to a scalar variable like&lt;code&gt; my $string ="@lines"; &lt;/code&gt;for use in later part of the script.&lt;/p&gt; 
&lt;code&gt;#!/usr/bin/perl –w
print "\n\nPlease type the filename: ";
$DNAfilename = &lt;STDIN&gt;;
chomp $DNAfilename;
# open the large file
unless ( open(DNAFILE, $DNAfilename) ) {
print "Cannot open file \"$DNAfilename\"\n\n";
exit;
} 
my @lines = &lt;DNAFILE&gt;; 
while (&lt;DNAFILE&gt;) {
  say $_;
} 
close DNAFILE;
$DNA = join( '', @lines);
# Remove whitespace
$DNA=~ s/\s//g;
# Count number of bases
$b=length($DNA);
print "\nNumber of bases: $b.";
# Count number of each base and nonbase
$A=0;$T=0;$G=0;$C=0;$e=0; 
while($DNA=~ /A/ig){$A++}
while($DNA=~ /T/ig){$T++}
while($DNA=~ /G/ig){$G++}
while($DNA=~ /C/ig){$C++}
while($DNA=~ /[^ATGC]/ig){$e++}
. . . . &lt;/code&gt;
&lt;p&gt;Command Prompt Results:&lt;/p&gt;
&lt;p&gt;C:\Documents and Settings\user\Desktop&gt;m3.pl&lt;/p&gt;
&lt;p&gt;Please type the filename of the DNA sequence data: chr1.txt&lt;/p&gt;
&lt;p&gt;Number of bases: 219475005.&lt;/p&gt;
&lt;p&gt;A=63473407; T=63582431; G=45425056; C=45435903; Errors(N)=1558208.&lt;/p&gt;
&lt;p&gt;Enter a motif to count nt between two such motifs: GAATTCCT&lt;/p&gt;
&lt;p&gt;I found the motif!&lt;/p&gt;
&lt;p&gt;Out of memory!&lt;/p&gt;
&lt;p&gt;C:\Documents and Settings\user\Desktop&gt;&lt;/p&gt;
&lt;p&gt;Thanks to Perl Monks for their quick reply in solving perl problems.&lt;/p&gt;
</field>
</data>
</node>
