Here is how you should probably do it by using a lookup hash for the substitutions and the input record separator.

#! perl # generate a single RE/hash for replacement open (PRIFILE, '<C:\temp.txt') or die; my %lookup; while (<PRIFILE>){ chomp; ($Cue, $Sound, $Pri) = split ("\t"); $lookup{$Sound} = $Pri; } close PRIFILE; my $re = join '|', keys %lookup; $re = qr/Name\s*=\s*($re)\s*;/; open (XAPFILE, 'C:\Documents and Settings\Nick\Desktop\040408 Work Fil +es\stranger.xap') or die; open (OUTFILE, '>C:\stranger.xap') or die; # set input record separator so we read a record at a time local $/ = "Sound\n{"; while (my $record = <XAPFILE>){ if ( $record =~ m/$re/ ) { my $sound = $1; my $delta_pri = $lookup{$sound}; # change existing pri unless ( $record =~ s/Priority\s*=\s*\d+/Priority=$delta_pri/ +) { # could not change so need to add $record =~ s/$sound/$sound\nPriority=$delta_pri;\n/; } } print OUTFILE $record; } close XAPFILE; close OUTFILE;

cheers

tachyon


In reply to Re: RegEx on 4MB file consumes of 2GB of ram before windows shuts it down (Memory Leak in 5.8.2) by tachyon
in thread RegEx on 4MB file consumes of 2GB of ram before windows shuts it down (Memory Leak in 5.8.2) by Ardemus

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.