Hi all,

Sometimes I have to change words inside text files. When this happens, and when I know what to search for, I use this program.

#!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" || $fi +le eq "tmp") { print "in $dir_to_process $file is processed\n"; open (INFILEHANDLE, "C:\\filestochange\\$file") or die "error open +ing"; open (OUTFILEHANDLE, ">C:\\filestochange\\tempfile8000") or die "e +rror opening"; while (<INFILEHANDLE>) { # 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 = <STDIN>;

In reply to Corrector by gok8000

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.