hello Monks,

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.

Pat

details 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;

In reply to Find and Replace multiple values in a file. by patair

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.