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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |