patair has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to update a value in a file using find and replace. $string1 =~ s/XXXGASPOINTIDXXX/656563/gi; which then writes to a second file which is then used in the second part of the script to update another value in the file using find and replace again
It is a bit basic but it seems to be doing what I want however it does not have time to write to second file eventhough I have sleep()s in the script at various points to allow files to be written to before it is used in the next part of the script.
thanks in advance.
Patdetails below
#!c:/perl/bin/perl.exe -w use strict; my $next_value; my @string1; my $string1; my @string2; my $string2; open (IN, "+<G203.xml"); open (OUT,">_G203.xml") || die ("Cannot open file"); @string1 = <IN>; seek IN,0,0; sleep (1); foreach $string1(@string1){ $string1 =~ s/XXXGASPOINTIDXXX/656563/gi; print OUT "$string1"; } close IN; sleep (3); print "\n sleeping ....\n"; open (IN2, "+<_G203.xml"); open (OUT2,">2_G203.xml") || die ("Cannot open file"); @string2 = <IN2>; seek IN2,0,0; sleep (1); foreach $string2(@string2){ $string2 =~ s/XXXMMREFXXX/62394732472856563/gi; print "$string2"; print OUT2 "$string2"; } close IN2;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Find and Replace multiple values in a file.
by scorpio17 (Canon) on Feb 08, 2011 at 14:13 UTC | |
by elef (Friar) on Feb 08, 2011 at 14:47 UTC | |
|
Re: Find and Replace multiple values in a file.
by moritz (Cardinal) on Feb 08, 2011 at 13:09 UTC | |
|
Re: Find and Replace multiple values in a file.
by elef (Friar) on Feb 08, 2011 at 13:28 UTC | |
|
Re: Find and Replace multiple values in a file.
by jethro (Monsignor) on Feb 08, 2011 at 13:49 UTC | |
|
Re: Find and Replace multiple values in a file.
by mvaline (Friar) on Feb 08, 2011 at 14:05 UTC | |
|
Re: Find and Replace multiple values in a file.
by CountZero (Bishop) on Feb 08, 2011 at 15:14 UTC | |
|
Re: Find and Replace multiple values in a file.
by locked_user sundialsvc4 (Abbot) on Feb 08, 2011 at 15:23 UTC | |
|
Re: Find and Replace multiple values in a file.
by CountZero (Bishop) on Feb 08, 2011 at 15:29 UTC |