in reply to Word Replacing

Perl (not PERL) does not, usually, loop through all the lines of the file; to make it do so see perlrun.

I've a few questions about your post:

You will have to do some more checks than just to see if the file is binary or not. Obviously, you should make sure that you've got correct rights to change the file. I would also advise that you copy the file, instead of changing it in place, until after you've thoroughly tested the code. You would, for example, not want to change source code in such a way as to introduce a syntax error or undefined external reference. And changing system("cp $oldfile $newfile"); to system("rm $oldfile $newfile"); could tend to be career inhibiting.

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

Replies are listed 'Best First'.
Re^2: Word Replacing
by xoddam (Novice) on Jun 04, 2007 at 21:41 UTC
    Hi, thankx for the help, BUT nothin of this is working ...

    I tryed all the examples which were mentioned here ...
    perl -pi.orig -e 's/original/substitute/g' <filename>


    or
    perl -spi -e 's/Bartholome/Richard/g' /path/to/folder/*


    The only thing what i achieved was, that my command line told me that i cant work with a file without and backoup or something like that ...

    Than even the full script, but it was full of errors, about 2-3 ...

    Guys, i know that i am like an insect but i really need help ... And you are my only hope - or i have to spend hours replacing a word by hand ... Please write me an exact way how to do that ...

    Than, if youll be in Slowakia lemme know, ill buy you a beer ... Thank you
      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 ..

        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