Hello,

I want to open a text file, look for a specific string, replace it with a new string, and write the line out to another file. For lines not containing the specific string, I want to write out as is.

I was wondering if it is possible to do it with a map or splice or grep command rather than a foreach loop.

Perhaps, I should be looking at some executable that replaces one string with another within a file?

I have resorted to a foreach loop.

Here is a snippet of my code:

          $currnodename = "AMACHINE";
          $oldnodename = "BMACHINE";
          $infile = "$ENV{FT}\\qld\\$msg.qli";
          $outfile = $ENV{TEMP} . "\\$task.tmp";

          open (INFILE, "<$infile") || die "Can not open $infile";
          open (OUTFILE, "+>$outfile") || die "Unable to open $outfile";
          while ($inline = <INFILE>)
             {
              chomp $inline;
              $inline =~ s/$oldnodename/$currnodename/g;
              print OUTFILE $inline;
             }
          close INFILE;
          close OUTFILE;


Thank you


_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to