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>;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Corrector
by hossman (Prior) on Dec 02, 2008 at 16:57 UTC | |
by jdporter (Paladin) on Dec 02, 2008 at 18:28 UTC | |
by hossman (Prior) on Dec 02, 2008 at 19:15 UTC | |
by jdporter (Paladin) on Dec 02, 2008 at 19:23 UTC | |
by dmorgo (Pilgrim) on Dec 29, 2008 at 01:21 UTC | |
Re: Corrector
by quinkan (Monk) on Dec 13, 2008 at 06:02 UTC | |
by gok8000 (Scribe) on Dec 28, 2008 at 15:49 UTC |
Back to
Cool Uses for Perl