Ardemus has asked for the wisdom of the Perl Monks concerning the following question:
I'll update after I've upgraded and tested my code.
--------------------------------------------------------
Hello folks. I'm exhausted, so please forgive me if this isn't well presented:
I have two test files. A data file of about 150,000 lines and a temp file with about 800 lines, each containing 3 values to use in my search expression (I only use two of them).
This code is intended to perform the substitutions and insertions, then save out the file to a new location.
Unfortunately, it consumes all of my physical memory in a few seconds, then chugs along until windows cuts it off at about 2GB and then kills it.
Although the code isn't as pretty or concise as it could be, is there anything here that can be changed to prevent this gross overuse of memory? It's as if the program is making a complete copy of the data for every iteration.
Any thoughts would be greatly appreciated. I've been trying to teach myself references, OO, modules, etc. to make a tool. That's been my life for the past 4 days. This is just a hack to get the task done on my deadline, and I'm at my wits end trying to make it finish.#! perl open (XAPFILE, 'C:\Documents and Settings\Nick\Desktop\040408 Work Fil +es\stranger.xap') or die; my $file = join ("",<XAPFILE>); my ($Cue, $Sound, $Pri); my $r_file = \$file; open (PRIFILE, '<C:\temp.txt') or die; open (OUTFILE, '>C:\stranger.xap') or die; while (<PRIFILE>){ { ($Cue, $Sound, $Pri) = split ("\t"); chomp ($Pri); if ($$r_file =~ s/(Sound\s*\{\s* Name\ =\ $Sound;\s* Priority\ =\ )([\d\D]*?);/$1$Pri;/xm){ print "Update $Sound > $Pri \n"; #print "'$1$Pri;'\n"; }elsif ($$r_file =~ s/(Sound\s*\{(\s*) Name\ =\ $Sound;\s*$)/$1$2Priority\ =\ $Pri;\n/xm){ + #print "$1$2Priority = $Pri;\n"; #print "1'$1'\n2'$2'\n3'$3'\n4'$4'\n"; print "Add $Sound > $Pri \n"; }else{ print "ERROR $Cue > $Sound > $Pri \n"; } } } print OUTFILE $file;
FYI - The data that is found is never more than four lines long, and each line is only a few dozen characters at most. I don't care if it takes 10 minutes to process, I just want it to finish.
Thanks
Nick
|
|---|