in reply to Re^2: Word Replacing
in thread Word Replacing

perl -p -i_ARCHIVE.txt -e "s/original/subst/g" <path to FILE>


good, afrer HOURS spend on googling the net i found this one ... Its workning on MS WIN without problems ...

It replaces the word, saves it under original form {name and file type} and creates a backup in form : original_ARCHIVE.txt ...

Nice ... And now the last thing what i need is, how to work with more files? If i type in as path to file:

C:/test/* - Does not work C:/test/*.* - Does not work C:/test/"*" - Does not work C:/test/"*.*" - Does not work


And so i have NO idea hot to let him work with all files in a folder, what you told me does not work ..

Replies are listed 'Best First'.
Re^4: Word Replacing
by swampyankee (Parson) on Jun 05, 2007 at 03:46 UTC

    You may have to forgo the single-line command, and do something akin to this (which is not tested)

    use strict; use warnings; my $newfolder = shift(@ARGV); use Tie::File; use Fcntl 'O_RDWR'; chdir($newfolder); my @list=glob("*"); foreach my $file (@list){ tie @array, 'Tie::File', $file, mode => O_RDWR or die "could not tie $ +file because...$!\n" foreach my $record (@array) { $record =~ s/$oldword/$newword/ig; } }

    Read docs on Tie::File; it will probably help.

    Also, read up on glob.

    emc

    Any New York City or Connecticut area jobs? I'm currently unemployed.

    There are some enterprises in which a careful disorderliness is the true method.

    —Herman Melville