<?xml version="1.0" encoding="windows-1252"?>
<node id="727451" title="Corrector" created="2008-12-02 10:47:56" updated="2008-12-02 10:47:56">
<type id="1980">
snippet</type>
<author id="703932">
gok8000</author>
<data>
<field name="doctext">
</field>
<field name="snippetdesc">
&lt;p&gt;Hi all,&lt;/p&gt;

&lt;p&gt;Sometimes I have to change words inside text files. When this happens, and when I know what to search for, I use this program.&lt;/p&gt;</field>
<field name="snippetcode">
&lt;CODE&gt;
#!c:/Perl/bin/Perl.exe
#
# corrector.pl
# changes words inside text files
# placed in the win directory C:\filestochange
# which is supposed to contain text files
#

my $dir_to_process = "C:\\filestochange";
opendir DH, $dir_to_process or die "Cannot open $dir_to_process: $!";

foreach $file (readdir DH) {
  unless ($file eq "." || $file eq ".." || $file eq "discarded" || $file eq "tmp") {
    print "in $dir_to_process $file is processed\n";
    open (INFILEHANDLE, "C:\\filestochange\\$file") or die "error opening";
    open (OUTFILEHANDLE, "&gt;C:\\filestochange\\tempfile8000") or die "error opening";
    while (&lt;INFILEHANDLE&gt;) {
      # chomp;
      s/this/that/; # substututes this with that
      s/one/two/; # substututes one with two
      print OUTFILEHANDLE;
    }
    close INFILEHANDLE;
    close OUTFILEHANDLE;
    rename "C:\\filestochange\\tempfile8000","C:\\filestochange\\$file";
  }
}

closedir DH;

print "\nDone (press enter key)\n";
$line = &lt;STDIN&gt;;
&lt;/CODE&gt;</field>
</data>
</node>
