in reply to Re: File handling
in thread File handling

perl -pi.bak -e 's/manulation/modification/' file.txt

Actually that will change the first (and supposedly unique) occurrence of 'manulation' in every line: indeed this makes sense, because the OP's request is sloppy to begin with. Anyway, he stresses that the substitution he wants must take place in a "particalur line" and mentions Tie::File, although to the effect of not wanting to use it. Thus I suspect he really wants the substitution to happen on a given line. But then... editi: given by what? If by a line number, say the tenth, then it's easy; you just have to enhance the above to:

perl -pi.bak -e '$.==10 and s/manulation/modification/' file.txt

If it's something different, then you have to tell us.

Replies are listed 'Best First'.
Re^3: File handling
by Anonymous Monk on May 31, 2007 at 03:34 UTC
    monks
    I have to use this in file manipulation like,
    open(FILE,"....") or die $!; while(<FILE>) { //Here Change part has to come } close FILE
    1)how to open a file like >+ or +<?.
    2)how to modify with in this file in while loop
    Thanks in advance
      1)how to open a file like >+ or +<?.

      From perldoc -f open:

      You can put a '+' in front of the '>' or '<' to indicate that you want both read and write access to the file; thus '+<' is almost always preferred for read/write updates--the '+>' mode would clobber the file first. You can't usually use either

      Curiously enough I wrote an explicit example yesterday in a thread with almost exactly the same subject as this one...